Dear all, I would like to ask your help concerning an error message I get. I have the following struct str(CRagentInTime[[1]]) List of 2 $ timelag: int 0 $ CRagent:List of 50 ..$ :List of 3 .. ..$ CRmap: num [1:256, 1:256] NA NA NA NA NA NA NA NA NA NA ... .. ..$ xy : num [1:2] 10 177 .. ..$ sr : num [1:49] -94.9 -92.8 -79.5 -97.6 -78.4 ... and I wanted to select all the sr fields for every of each one of the 50 CRagent Lists I have. So I tried something like str(CRagentInTime[[1]][[2]][[1:10]]$sr) and I get a message that Error in CRagentInTime[[1]][[2]][[1:10]] : recursive indexing failed at level 3 strange to me is that this one works str(CRagentInTime[[1]][[2]][[1]]$sr) num [1:49] -106 -92.9 -101.3 -81.9 -96.7 ... I would like to thank you in advance for your help Best Regards Alex
On 05/09/2011 08:58 AM, Alaios wrote:> Dear all, > I would like to ask your help concerning an error message I get. > > I have the following struct > > str(CRagentInTime[[1]]) > List of 2 > $ timelag: int 0 > $ CRagent:List of 50 > ..$ :List of 3 > .. ..$ CRmap: num [1:256, 1:256] NA NA NA NA NA NA NA NA NA NA ... > .. ..$ xy : num [1:2] 10 177 > .. ..$ sr : num [1:49] -94.9 -92.8 -79.5 -97.6 -78.4 ... > > and I wanted to select all the sr fields for every of each one of the 50 CRagent Lists I have. > > So I tried something like > > str(CRagentInTime[[1]][[2]][[1:10]]$sr) and I get a message that > Error in CRagentInTime[[1]][[2]][[1:10]] : > recursive indexing failed at level 3Selecting multiple elements of a list using an expression like [[1:10]] does not work. For example: x <- list("a","b") x[[1:2]] produces Error in x[[1:2]] : subscript out of bounds In general, the expression x[[1:2]] is not meaningful, as the elements of the list may be of different type, with no way to concatenate them.> > strange to me is that this one works > > str(CRagentInTime[[1]][[2]][[1]]$sr) > num [1:49] -106 -92.9 -101.3 -81.9 -96.7 ... > > > I would like to thank you in advance for your help > Best Regards > Alex >_______________________ Patrick Breheny Assistant Professor Department of Biostatistics Department of Statistics University of Kentucky
So the only thing that might work is a for..loop to collect all these together? Best REgards Alex --- On Mon, 5/9/11, Patrick Breheny <patrick.breheny at uky.edu> wrote:> From: Patrick Breheny <patrick.breheny at uky.edu> > Subject: Re: [R] Recursive Indexing Failed > To: "Alaios" <alaios at yahoo.com> > Cc: "R-help at r-project.org" <R-help at r-project.org> > Date: Monday, May 9, 2011, 2:18 PM > On 05/09/2011 08:58 AM, Alaios > wrote: > > Dear all, > > I would like to ask your help concerning an error > message I get. > > > > I have the following struct > > > > str(CRagentInTime[[1]]) > > List of 2 > >???$ timelag: int 0 > >???$ CRagent:List of 50 > >? ? ..$ :List of 3 > >? ? .. ..$ CRmap: num [1:256, 1:256] NA NA NA > NA NA NA NA NA NA NA ... > >? ? .. ..$ xy???: num [1:2] 10 > 177 > >? ? .. ..$ sr???: num [1:49] > -94.9 -92.8 -79.5 -97.6 -78.4 ... > > > > and I wanted to select all the sr fields for every of > each one of the 50 CRagent Lists I have. > > > > So I tried something like > > > > str(CRagentInTime[[1]][[2]][[1:10]]$sr) and I get a > message that > > Error in CRagentInTime[[1]][[2]][[1:10]] : > >? ? recursive indexing failed at level 3 > > Selecting multiple elements of a list using an expression > like [[1:10]] > does not work.? For example: > > x <- list("a","b") > x[[1:2]] > > produces > > Error in x[[1:2]] : subscript out of bounds > > In general, the expression x[[1:2]] is not meaningful, as > the elements > of the list may be of different type, with no way to > concatenate them. > > > > > strange to me is that this one works > > > > str(CRagentInTime[[1]][[2]][[1]]$sr) > >???num [1:49] -106 -92.9 -101.3 -81.9 > -96.7 ... > > > > > > I would like to thank you in advance for your help > > Best Regards > > Alex > > > _______________________ > Patrick Breheny > Assistant Professor > Department of Biostatistics > Department of Statistics > University of Kentucky >
On May 9, 2011, at 15:24 , Alaios wrote:> So the only thing that might work is a for..loop to collect all these together?An implicit loop using lapply/sapply might be more like it: lapply(CRagentInTime[[1]]$CRagent[1:10], "[[", "sr") Notice that fancy indexing usually requires "[", not "[[".> > Best REgards > Alex > > --- On Mon, 5/9/11, Patrick Breheny <patrick.breheny at uky.edu> wrote: > >> From: Patrick Breheny <patrick.breheny at uky.edu> >> Subject: Re: [R] Recursive Indexing Failed >> To: "Alaios" <alaios at yahoo.com> >> Cc: "R-help at r-project.org" <R-help at r-project.org> >> Date: Monday, May 9, 2011, 2:18 PM >> On 05/09/2011 08:58 AM, Alaios >> wrote: >>> Dear all, >>> I would like to ask your help concerning an error >> message I get. >>> >>> I have the following struct >>> >>> str(CRagentInTime[[1]]) >>> List of 2 >>> $ timelag: int 0 >>> $ CRagent:List of 50 >>> ..$ :List of 3 >>> .. ..$ CRmap: num [1:256, 1:256] NA NA NA >> NA NA NA NA NA NA NA ... >>> .. ..$ xy : num [1:2] 10 >> 177 >>> .. ..$ sr : num [1:49] >> -94.9 -92.8 -79.5 -97.6 -78.4 ... >>> >>> and I wanted to select all the sr fields for every of >> each one of the 50 CRagent Lists I have. >>> >>> So I tried something like >>> >>> str(CRagentInTime[[1]][[2]][[1:10]]$sr) and I get a >> message that >>> Error in CRagentInTime[[1]][[2]][[1:10]] : >>> recursive indexing failed at level 3 >> >> Selecting multiple elements of a list using an expression >> like [[1:10]] >> does not work. For example: >> >> x <- list("a","b") >> x[[1:2]] >> >> produces >> >> Error in x[[1:2]] : subscript out of bounds >> >> In general, the expression x[[1:2]] is not meaningful, as >> the elements >> of the list may be of different type, with no way to >> concatenate them. >> >>> >>> strange to me is that this one works >>> >>> str(CRagentInTime[[1]][[2]][[1]]$sr) >>> num [1:49] -106 -92.9 -101.3 -81.9 >> -96.7 ... >>> >>> >>> I would like to thank you in advance for your help >>> Best Regards >>> Alex >>> >> _______________________ >> Patrick Breheny >> Assistant Professor >> Department of Biostatistics >> Department of Statistics >> University of Kentucky >> > > ______________________________________________ > 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.-- Peter Dalgaard Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com