[R] creating matrices from lists
Peter Dalgaard
pdalgd at gmail.com
Tue Sep 21 08:09:07 CEST 2010
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.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-help
mailing list