问题
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:13
Then, how do I use lapply
?
回答1:
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)
来源:https://stackoverflow.com/questions/35320991/convert-several-columns-from-integer-to-numeric-in-r-data-frame