Convert multiple columns from integer to numeric in R data.frame

I would like to convert columns 2 to 13 (last) from integer to numeric.

For a single column, I use the following code:

dades$V3 <- as.numeric(dades$V3)

I want to convert columns 2 to 13 using the same command. I create this vector:

dades<-2:13

Then how should I use lapply?

+9
source share
1 answer

We can use lapplya subset of the dataset ( dades[2:13]), convert to numericand assign it back to these columns.

dades[2:13] <- lapply(dades[2:13], as.numeric)
+13
source

Source: https://habr.com/ru/post/1628165/


All Articles