Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid Length Argument

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?

like image 633
Adhiraj Chattopadhyay Avatar asked Mar 06 '23 20:03

Adhiraj Chattopadhyay


1 Answers

Try using as.numeric instead of numeric:

dat <- as.data.frame(lapply(dat, as.numeric))
like image 137
RHertel Avatar answered Mar 20 '23 22:03

RHertel