Skip to content

numeric operations w/ lists

3 messages · Afshartous, David, Sean Davis, Bert Gunter

#
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:
Error in X - rep(Y 20) : non-numeric argument to binary operator

I tried several methods w/o success.  Any suggestions kindly
appreciated.

Thanks,
Dave

ps - please copy afshar at miami.edu in the reply, as I've had 
problems receiving the daily digest.
#
On 8/9/05 12:21 PM, "Afshartous, David" <afshart at exchange.sba.miami.edu>
wrote:
See ?lapply.  Something like:


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

Hope this helps.

Sean
#
Suggestions:

1. Read the relevant sections of "An Introduction to R" and the R language
definition to learn how to work with lists. 
3. ?lapply to learn how to use the apply family on lists

Hint: sapply(X,"-",y=Y)

The above references will tell you what these hieroglyphics mean and what
you get. Also why
matrix(unlist(X)-Y,nr=65) 

gives you the same result.

-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA
 
"The business of the statistician is to catalyze the scientific learning
process."  - George E. P. Box