I have a list of dataframes that I want to convert two columns to numeric in each object of the list.
This is an example of the list I have:
y <- list(data.frame(Timestamp=c("2016-11-14","2016-11-14","2016-11-14","2016-11-14"),
x1=as.character(c(6.225462,5.684068,4.849579,5.223110)),
x2=as.character(c(1.362822,1.069084,0.756673,0.950383))),
data.frame(Timestamp=c("2016-11-14 19:00:00","2016-11-14 19:10:00","2016-11-14 19:20:00","2016-11-14 19:30:00"),
x1=as.character(c(6.225462,5.684068,4.849579,5.223110)),
x2=as.character(c(1.362822,1.069084,0.756673,0.950383))))
I want to convert columns x1
and x2
of each object of the list to a numeric value with as.numeric
but keeping the list.
I tried with this:
y[,-1] <- lapply(y[,-1] , as. numeric)
But this code doesn't work. I get the error
Error in y[, -1] : incorrect number of dimensions
I know y[,-1]
would work in a single dataframe but I'm not sure how to handle it in a list.
Please some help.