[R] numeric operations w/ lists

Sean Davis sdavis2 at mail.nih.gov
Tue Aug 9 19:01:27 CEST 2005


On 8/9/05 12:21 PM, "Afshartous, David" <afshart at exchange.sba.miami.edu>
wrote:

> 
> Hello all,
> 
> X is a list of 20 lists, and each individual list has 65 elements.
> 
> Y is a list of 65 elements.
> 
> WANT:  subtract Y from each of the 20 lists in X.
> 
> Here's what I tried and the error messages:
> 
>> X - rep(Y, 20)

See ?lapply.  Something like:


NewX <- lapply(X,function(tmp) {tmp-Y})

Hope this helps.

Sean




More information about the R-help mailing list