Convert several columns from integer to numeric in R data.frame
Emily Wong
I would like to convert columns from 2 to 13 (the last one) from integer to numeric.
For one column, I use the following code:
dades$V3 <- as.numeric(dades$V3)I want to convert columns from 2 to 13 with the same command. I create this vector:
dades<-2:13Then, how do I use lapply?
1 Answer
We can use lapply on the subset of dataset (dades[2:13]), convert to numeric and assign it back to those columns.
dades[2:13] <- lapply(dades[2:13], as.numeric) 3