Invalid Length Argument

Adhiraj Chattopadhyay picture Adhiraj Chattopadhyay · Jul 10, 2018 · Viewed 9k times · Source

I want to convert all the coloumns of my dataframe to numeric format. So I use lapply

 data.frame(lapply(dat, numeric))

But this is showng me an invalid length argument error. However, it is working when I tried with individual coloumns.

 lapply(dat$x.Type, numeric)

But then again I am left to wonder how to update the orginal dataframe with this.

I am guessing the solution to my problem is to run a loop applying lapply through all the coloumns . The problem is I am having trouble figuring out how to do that.

Could somebody help me?

Answer

RHertel picture RHertel · Jul 10, 2018

Try using as.numeric instead of numeric:

dat <- as.data.frame(lapply(dat, as.numeric))