[R] merging columns

Antonio Olinto aolinto at bignet.com.br
Sun Nov 4 14:55:33 CET 2001


Dear R-list members

I’m trying, without success, to create new a column (YQ) into a data.frame
from another two columns (Y and Q):
Y       Q   YQ
1998  1    98-1

I’ve tried several commands. cbind, for instance, gives me "98" "-" "1" and
not 98-1.

Could someone help me? Many thanks.

Antonio Olinto


Example:

> data.dat <- data.frame(rep(1998:2001,c(4,4,4,4)),rep(1:4,4))
> names(data.dat)<- c("Y","Q")
> attach(data.dat)
> cbind(substring(Y,3,4),"-",Q)
                     Q
 [1,] "98" "-" "1"
 [2,] "98" "-" "2"
 [3,] "98" "-" "3"
 [4,] "98" "-" "4"
 [5,] "99" "-" "1"
 [6,] ...

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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 mailing list