Friday, 15 February 2013

r - Data frame not getting converted to numeric -



r - Data frame not getting converted to numeric -

i have 100 files in list access using:

my.data[[1]], my.data[[2]] ... my.data[[100]]

each of these data.frame containing 202 columns , 2080 rows , convert them numeric class. tried with:

for (i in 1:100) { my.data[[i]] <- sapply(my.data[[i]], as.numeric) }

but when check class after running loop using:

class(my.data[[1]])

i class "matrix".

of course, tried check them 1 of data.frames before looping; gave me same result.

please help. perchance wrong?

try:

set.seed(49) my.data <- lapply(1:5, function(x) as.data.frame(matrix(as.character(sample(20,5*6,replace=true)), ncol=6),stringsasfactors=f)) my.data[] <- lapply(my.data, function(x) {x[] <-lapply(x, as.numeric);x}) str(my.data)

r

No comments:

Post a Comment