Rajarshi Guha
2009-Jun-23 12:11 UTC
[R] an idiom to handle i'th element of a set of lists simultaneously
Hi, I have 3 lists, x, y, z and I'd like to perform a calculation over all the lists simultaneously. If it were a single list I could use lapply, but for more than one list I'm using a for loop. Is there an idiom that would let me use something like lapply, but the function specified to lappy would have access to an element from each list? (In Python, I would have used for a,b,c in zip(x,y,z): ...) Thanks, -- Rajarshi Guha [[alternative HTML version deleted]]
Henrique Dallazuanna
2009-Jun-23 12:21 UTC
[R] an idiom to handle i'th element of a set of lists simultaneously
If I understand, you can use rapply for this. On Tue, Jun 23, 2009 at 9:11 AM, Rajarshi Guha <rajarshi.guha@gmail.com>wrote:> Hi, I have 3 lists, x, y, z and I'd like to perform a calculation over all > the lists simultaneously. If it were a single list I could use lapply, but > for more than one list I'm using a for loop. Is there an idiom that would > let me use something like lapply, but the function specified to lappy would > have access to an element from each list? (In Python, I would have used for > a,b,c in zip(x,y,z): ...) > > Thanks, > > -- > Rajarshi Guha > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Rajarshi Guha
2009-Jun-23 15:58 UTC
[R] an idiom to handle i'th element of a set of lists simultaneously
Thanks to all who replied. mapply does the trick On Tue, Jun 23, 2009 at 8:11 AM, Rajarshi Guha <rajarshi.guha@gmail.com>wrote:> Hi, I have 3 lists, x, y, z and I'd like to perform a calculation over all > the lists simultaneously. If it were a single list I could use lapply, but > for more than one list I'm using a for loop. Is there an idiom that would > let me use something like lapply, but the function specified to lappy would > have access to an element from each list? (In Python, I would have used for > a,b,c in zip(x,y,z): ...) > > Thanks, > > -- > Rajarshi Guha >-- Rajarshi Guha [[alternative HTML version deleted]]