Re: [R] Extracting elements from a nested list

2010-10-19 Thread Erich Neuwirth
mapply(function(x1,x2)x1[[x2]],all.predicted.values,max.growth,SIMPLIFY=FALSE) gives a list of factors. On 10/18/2010 8:40 PM, Gregory Ryslik wrote: Hi Everyone, This is closer to what I need but this returns me a matrix where each element is a factor. Instead I would want a list of lists.

[R] Extracting elements from a nested list

2010-10-18 Thread Gregory Ryslik
Hi, I have a list of n items and the ith element has m_i elements within it. I want to do something like: predicted.values- lapply(all.predicted.values,'[[',max.growth[[i]]) Where max.growth[[i]] is the element I want to extract from each of the ith predicted elements. Thus, for example, I

Re: [R] Extracting elements from a nested list

2010-10-18 Thread Henrique Dallazuanna
Try this: diag(sapply(all.predicted.values, '[[', 'max.growth')) On Mon, Oct 18, 2010 at 12:59 PM, Gregory Ryslik rsa...@comcast.net wrote: Hi, I have a list of n items and the ith element has m_i elements within it. I want to do something like: predicted.values-

Re: [R] Extracting elements from a nested list

2010-10-18 Thread Gregory Ryslik
Unfortunately, that gives me null everywhere. Here's the data I have for all.predicted.values and max.growth. Perhaps this will help. Thus I want all.predicted.values[[1]][[4]] then all.predicted.values[[2]][3]] and then all.predicted.values[[3]][[4]]. I've attached what your statement outputs

Re: [R] Extracting elements from a nested list

2010-10-18 Thread jim holtman
Try posting your data using 'dput' so it is easily read for testing. On Mon, Oct 18, 2010 at 11:17 AM, Gregory Ryslik rsa...@comcast.net wrote: Unfortunately, that gives me null everywhere. Here's the data I have for all.predicted.values and max.growth. Perhaps this will help. Thus I want

Re: [R] Extracting elements from a nested list

2010-10-18 Thread Erich Neuwirth
You probably need mapply since you have 2 list of arguments which you want to use in sync mapply(function(x1,x2)x1[[x2]],all.predicted.values,max.growth) might be what you want. On Oct 18, 2010, at 5:17 PM, Gregory Ryslik wrote: Unfortunately, that gives me null everywhere. Here's the data

Re: [R] Extracting elements from a nested list

2010-10-18 Thread Gregory Ryslik
Hi Everyone, This is closer to what I need but this returns me a matrix where each element is a factor. Instead I would want a list of lists. The first entry of the list should equal the first column of the matrix that mapply makes, the second entry to the second column etc... I've attached

Re: [R] Extracting elements from a nested list

2010-10-18 Thread Gregory Ryslik
Hi, It seems that the files did not make it through the mailer. Perhaps it didn't like my extensions. I have now attached the files as .txt's as well as copied in the contents of each file: list(list(structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,

Re: [R] Extracting elements from a nested list

2010-10-18 Thread jim holtman
Does this do what you want: x - lapply(seq_along(MaxGrowth), function(.num){ + AllPredictedValues[[.num]][[MaxGrowth[[.num + }) x [[1]] [1] 2 1 2 2 2 2 0 2 2 0 0 2 2 0 0 2 2 1 2 0 1 1 0 0 0 2 0 0 0 2 2 0 0 1 0 0 2 0 1 0 2 0 0 2 1 0 0 0 2 1 0 2 2 [54] 2 2 0 2 0 1 0 2 0 1 0 0 0 1 0 0 2