Dear all, I have a list of arrays : foo<-list(A = c(1,3), B =c(1, 2), C = c(3, 1))> foo$A [1] 1 3 $B [1] 1 2 $C [1] 3 1 I want to use all foo$A , foo$B and foo$C in a test :> foo$A[1] == 1[1] TRUE> foo[[1]][1] == 1[1] TRUE> foo[[1:3]][1] == 1Error in foo[[1:3]] : recursive indexing failed at level 2 Is there a regular expression I can use ?
You could use: mapply(`==`, sapply(foo,`[`,1),1) #??? A???? B???? C # TRUE? TRUE FALSE A.K. On Thursday, June 26, 2014 10:50 PM, ce <zadig_1 at excite.com> wrote: Dear all, I have a list of arrays : foo<-list(A = c(1,3), B =c(1, 2), C = c(3, 1))> foo$A [1] 1 3 $B [1] 1 2 $C [1] 3 1 I want to use all foo$A , foo$B and foo$C in a test :> foo$A[1] == 1[1] TRUE> foo[[1]][1] == 1[1] TRUE> foo[[1:3]][1] == 1Error in foo[[1:3]] : recursive indexing failed at level 2 Is there a regular expression I can use ? ______________________________________________ R-help at 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.
Bert Gunter
2014-Jun-27 03:29 UTC
[R] Error in foo[[1:3]] : recursive indexing failed at level 2
foo[[1:3]] asks for the 3rd member of the second component of the list that is nested within the 1st component of the top level list. You have no nested sublists, so this is clearly nonsense. You need to re-read ?"[" or consult The Introduction to R or other online tutorial to understand the semantics of "[[" with a vector of indices as argument. Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." Clifford Stoll On Thu, Jun 26, 2014 at 7:49 PM, ce <zadig_1 at excite.com> wrote:> Dear all, > > I have a list of arrays : > > foo<-list(A = c(1,3), B =c(1, 2), C = c(3, 1)) > >> foo > $A > [1] 1 3 > > $B > [1] 1 2 > > $C > [1] 3 1 > > I want to use all foo$A , foo$B and foo$C in a test : > >> foo$A[1] == 1 > [1] TRUE >> foo[[1]][1] == 1 > [1] TRUE >> foo[[1:3]][1] == 1 > Error in foo[[1:3]] : recursive indexing failed at level 2 > > > Is there a regular expression I can use ? > > ______________________________________________ > R-help at 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.