Re: [R] How to iteratively extract elements out of a list

2006-08-28 Thread Petr Pikal
Hi try to do it without loop lapply(m,function(x) x[x2]) HTH Petr On 25 Aug 2006 at 13:52, xpRt.wannabe wrote: Date sent: Fri, 25 Aug 2006 13:52:51 -0500 From: xpRt.wannabe [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Subject:

Re: [R] How to iteratively extract elements out of a list

2006-08-26 Thread Patrick Burns
sub.m - lapply(m, function(x)x[x2]) sub.m [[1]] [1] 3 4 [[2]] [1] 4 5 [[3]] [1] 4 sub.m[unlist(lapply(sub.m, function(x) length(x) == 2))] [[1]] [1] 3 4 [[2]] [1] 4 5 sub4.m - lapply(m, function(x)x[x4]) sub4.m[unlist(lapply(sub4.m, function(x) length(x) 0))] [[1]] [1] 5 Patrick

Re: [R] How to iteratively extract elements out of a list

2006-08-26 Thread Mark Lyman
lapply(m,function(x)x[x2]) [[1]] [1] 3 4 [[2]] [1] 4 5 [[3]] [1] 4 __ R-help@stat.math.ethz.ch 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

Re: [R] How to iteratively extract elements out of a list

2006-08-26 Thread xpRt.wannabe
Thank you! On 8/26/06, Patrick Burns [EMAIL PROTECTED] wrote: sub.m - lapply(m, function(x)x[x2]) sub.m [[1]] [1] 3 4 [[2]] [1] 4 5 [[3]] [1] 4 sub.m[unlist(lapply(sub.m, function(x) length(x) == 2))] [[1]] [1] 3 4 [[2]] [1] 4 5 sub4.m - lapply(m, function(x)x[x4])

Re: [R] How to iteratively extract elements out of a list

2006-08-26 Thread Patrick Connolly
On Sat, 26-Aug-2006 at 09:57AM +0100, Patrick Burns wrote: | sub.m - lapply(m, function(x)x[x2]) | sub.m | [[1]] | [1] 3 4 | | [[2]] | [1] 4 5 | | [[3]] | [1] 4 | | sub.m[unlist(lapply(sub.m, function(x) length(x) == 2))] | [[1]] | [1] 3 4 | | [[2]] | [1] 4 5 | | sub4.m - lapply(m,

Re: [R] How to iteratively extract elements out of a list

2006-08-26 Thread Gabor Grothendieck
On 8/26/06, Patrick Connolly [EMAIL PROTECTED] wrote: On Sat, 26-Aug-2006 at 09:57AM +0100, Patrick Burns wrote: | sub.m - lapply(m, function(x)x[x2]) | sub.m | [[1]] | [1] 3 4 | | [[2]] | [1] 4 5 | | [[3]] | [1] 4 | | sub.m[unlist(lapply(sub.m, function(x) length(x) == 2))] |

Re: [R] How to iteratively extract elements out of a list

2006-08-25 Thread jim holtman
try this: set.seed(123) tmpf - function() { + x - rpois(rpois(1,4),2) + } n - 3 m - replicate(n,tmpf()) m [[1]] [1] 3 2 4 [[2]] [1] 0 2 4 2 2 5 2 [[3]] [1] 2 0 4 1 0 lapply(m, function(x)x[x2]) [[1]] [1] 3 4 [[2]] [1] 4 5 [[3]] [1] 4 On 8/25/06, xpRt.wannabe [EMAIL PROTECTED] wrote:

Re: [R] How to iteratively extract elements out of a list

2006-08-25 Thread xpRt.wannabe
Jim and Patrick, Both of you made the same suggestion, which works great! A follow-up question: Suppose I change the condition 'x2' in 'lapply' to 'x4', as follows: set.seed(123) tmpf - function() { x - rpois(rpois(1,4),2) } n - 3 m - replicate(n,tmpf()) m sub.m - lapply(m, function(x)x[x4]) #

Re: [R] How to iteratively extract elements out of a list

2006-08-25 Thread xpRt.wannabe
Yet another question: Let's say I do the following: set.seed(123) tmpf - function(){ x - rpois(rpois(1,4),2) } n - 3 m - replicate(n, tmpf()) m sub.m - lapply(m, function(x)x[x2]) 'sub.m' gives me: [[1]] [1] 3 4 [[2]] [1] 4 5 [[3]] [1] 4 The question is: What do I need to do such that I