Of Bert Gunter
Sent: Thursday, April 25, 2013 7:54 AM
To: ted.hard...@wlandres.net
Cc: R mailing list
Subject: Re: [R] Decomposing a List
Well, what you really want to do is convert the list to a matrix, and
it can be done directly and considerably faster than with the
(implicit) looping
Greetings!
For some reason I am not managing to work out how to do this
(in principle) simple task!
As a result of applying strsplit() to a vector of character strings,
I have a long list L (N elements), where each element is a vector
of two character strings, like:
L[1] = c(A1,B1)
L[2] =
Dear Dr. Harding,
Try
sapply(L, [, 1)
sapply(L, [, 2)
HTH,
Jorge.-
On Thu, Apr 25, 2013 at 8:16 PM, Ted Harding ted.hard...@wlandres.netwrote:
Greetings!
For some reason I am not managing to work out how to do this
(in principle) simple task!
As a result of applying strsplit() to a
Thanks, Jorge, that seems to work beautifully!
(Now to try to understand why ... but that's for later).
Ted.
On 25-Apr-2013 10:21:29 Jorge I Velez wrote:
Dear Dr. Harding,
Try
sapply(L, [, 1)
sapply(L, [, 2)
HTH,
Jorge.-
On Thu, Apr 25, 2013 at 8:16 PM, Ted Harding
To: r-help@r-project.org
Cc:
Sent: Thursday, April 25, 2013 6:16 AM
Subject: [R] Decomposing a List
Greetings!
For some reason I am not managing to work out how to do this
(in principle) simple task!
As a result of applying strsplit() to a vector of character strings,
I have a long list L (N
Well, what you really want to do is convert the list to a matrix, and
it can be done directly and considerably faster than with the
(implicit) looping of sapply:
f1 - function(l)sapply(l,[,1)
f2 - function(l)matrix(unlist(l),nr=2)
l -
On Apr 25, 2013, at 7:53 AM, Bert Gunter wrote:
Well, what you really want to do is convert the list to a matrix, and
it can be done directly and considerably faster than with the
(implicit) looping of sapply:
f1 - function(l)sapply(l,[,1)
f2 - function(l)matrix(unlist(l),nr=2)
l -
Well...
WIth the same list,l,as before:
system.time(x3 - simplify2array(l))
user system elapsed
2.110.052.20
system.time(x2 - f2(l)) ## the matrix(unlist(...)) one
user system elapsed
0.110.000.11
identical(x2,x3)
[1] TRUE
So kind of a big difference if you
8 matches
Mail list logo