On 09/21/2010 05:02 AM, Gregory Ryslik wrote:
> Hi,
> 
> I think I've found away around that issue. The following works. If
this method is inefficient and one has something faster, I'll appreciate
it though!
> 
> lapply(mylist, function(x) as.numeric(as.character(x)))

You could avoid making them factors in the first place....

Otherwise, the common trick is as.numeric(levels(x))[x] or, if you are
sure that the levels are always 0/1, c(0,1)[x]. Of course if that is
true you could just accept the 1/2 solution and subtract 1 at the end.
(But beware that you might have one element as a factor with a single
level "1", and that would get treated exactly the same as a factor with
only "0"...)

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: pd....@cbs.dk  Priv: pda...@gmail.com

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to