Aleksey Naumov <naumov at acsu.buffalo.edu> writes:
> How do I add a new column to data - 'var2' in which I group values
in
> 'var1',
> for example:
>
> var1 var2
> 1 1 4
> 2 2 4
> 3 3 5
>
> It's got to be simple, but I can't find it...
data$var2 <- c(4,4,5)[data$var1]
or
data <- transform(data, var2=c(4,4,5)[var1])
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._