[R] Concatenating variables

Gabor Grothendieck ggrothendieck at myway.com
Wed Aug 4 22:50:14 CEST 2004

Doran, Harold <HDoran <at> air.org> writes:

: I'm having difficulty with something I believe is very simple, but I'm
: stuck. I have a large data frame that took days to clean and prepare.
: All I now need to do is concatenate three variables into a single
: column. For example, I have tenn$up, tenn$down, and tenn$stable which
: all have values of 1 or 0. I simply want to put all three columns
: together to create a pattern (e.g., 111, 101, 001).
: I tried c(tenn$up,tenn$down,tenn$stable)
: But this isn't working. Thanks for any help offered.

Several people have already mentioned paste, which returns a character
result, and two other solutions, depending on what you are looking for, 

   with(tenn, 100 * up + 10 * down + stable)  # numeric result

   with(tenn, interaction(up, down, stable, sep =""))  # factor result

More information about the R-help mailing list