On Tue, 2005-06-28 at 17:23 -0400, Anna Oganyan wrote: > Dear List, > How can I convert a list with elements being character strings, like: > "c(1,2,3,4)", “c(1,3,4,2) … to a list with elements as numerical > vectors: c(1,2,3,4), c(1,3,4,2)…? > Thanks! > Anna
> l <- list("c(1,2,3,4)", "c(1,3,4,2)") > l [[1]] [1] "c(1,2,3,4)" [[2]] [1] "c(1,3,4,2)" Now use lapply() over each list element in 'l', converting the character vectors to R expressions and then evaluating them: > lapply(l, function(x) eval(parse(text = x))) [[1]] [1] 1 2 3 4 [[2]] [1] 1 3 4 2 See ?lapply, ?eval and ?parse. HTH, Marc Schwartz ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html