Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

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

Writer 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:13

Then, 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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy