Heym, Peter-Paul
2010-Feb-25 09:10 UTC
[R] how to fast extract values from different list elements
hi, I have a list L having more than 14000 Elements, each of these contains an array of about length 1200.> L[[1]][26:30] # e.g. print 5 entries of first element of L[1] 0.0000000 6.7982652 114.4737184 89.7328239 3.2001664 Furthermore I get two arrays A and B of same length as input. A<-c(4,7,9,34,463,788) B<-c(50,67,87,361,45,89) I would like to extract (or print or save) certain values of L which I do in the following (inefficient) way at the moment: for (i in 1:length(A) { print( L[[A[i]]][B[i]] ) } this works fine but it is very slow (since A and B can be very large and I have to repeat this about 5000 times). I would like to make this faster using e.g. apply or lapply but I didn't get it work using these methods. Does anybody know an EFFICIENT or FAST way extract the values from L using the values from A and B? thanks for your answers. Peter [[alternative HTML version deleted]]
Tom Short
2010-Feb-25 13:36 UTC
[R] how to fast extract values from different list elements
On Thu, Feb 25, 2010 at 4:10 AM, Heym, Peter-Paul <pheym at ipb-halle.de> wrote:> this works fine but it is very slow (since A and B can be very large and I > have to repeat this about 5000 times). I would like to make this faster using > e.g. apply or lapply but I didn't get it work using these methods. Does > anybody know an EFFICIENT or FAST way extract the values from L using the > values from A and B?Instead of L[[A[i]]][B[i]], try L[A][B] - Tom
Dear Peter, What data types does your list contain? Have you tried treating the list as a data frame or matrix? KeithC. -----Original Message----- From: Heym, Peter-Paul [mailto:pheym at ipb-halle.de] Sent: Thursday, February 25, 2010 2:11 AM To: r-help at R-project.org Subject: [R] how to fast extract values from different list elements hi, I have a list L having more than 14000 Elements, each of these contains an array of about length 1200.> L[[1]][26:30] # e.g. print 5 entries of first element of L[1] 0.0000000 6.7982652 114.4737184 89.7328239 3.2001664 Furthermore I get two arrays A and B of same length as input. A<-c(4,7,9,34,463,788) B<-c(50,67,87,361,45,89) I would like to extract (or print or save) certain values of L which I do in the following (inefficient) way at the moment: for (i in 1:length(A) { print( L[[A[i]]][B[i]] ) } this works fine but it is very slow (since A and B can be very large and I have to repeat this about 5000 times). I would like to make this faster using e.g. apply or lapply but I didn't get it work using these methods. Does anybody know an EFFICIENT or FAST way extract the values from L using the values from A and B? thanks for your answers. Peter [[alternative HTML version deleted]]
Possibly Parallel Threads
- SSOAP: arguments passed as
- SSOAP fails with .types[[1]] : subscript out of bounds
- Default R-3.4.0 RC CXXFLAGS without -O2 on x86_64-linux-gnu with g++-5.4.0 causes WARNING from stl_list.h
- help with SSOAP (can't find working examples)
- Error Correcting Codes, Simplex