[R] modifying a vector
wilson at visi.com
Sun Jun 30 06:47:55 CEST 2002
Thanks to all who offered suggestions after my initial query to the list.
I've been busy trying to absorb the docs as fast as possible, but this
little thing has me stumped for the moment.
I'm creating a random sample of 100 item and saving it to a vector named
'iq'. I'd like to create a second vector (iq_prime, say) by adding 20 to
each element of the 'iq' vector. Here's what I've tried.
> iq <- rnorm(100, 80, 15)
> t(dstats(iq)) # Thanks Brett Magill
mean sd variance min max unique n miss skewness
[1,] 78.628 14.223 202.302 49.079 121.294 100 100 0
> iq_prime <- sapply(iq, function(x)x+20)
mean sd variance min max unique n miss
[1,] 98.628 14.223 202.302 69.079 141.294 100 100 0
Nothing is being done with 'iq_prime' apparently, but 'iq' gets changed.
Any suggestions? I guess I understand that the function is being run on
'iq', but why doesn't the vector get saved as 'iq_prime'? And how would
I do this without modifying 'iq'?
Tim Wilson | Visit Sibley online: | Check out:
Henry Sibley HS | http://www.isd197.org | http://www.zope.com
W. St. Paul, MN | | http://slashdot.org
wilson at visi.com | <dtml-var pithy_quote> | http://linux.com
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
More information about the R-help