Hi all: 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. Harold [[alternative HTML version deleted]]
Try something like: paste(tenn$up, tenn$down, tenn$stable, collapse="") HTH, Andy> From: Doran, Harold > > Hi all: > > > > 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. > > > > Harold > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >
Doran, Harold wrote:> Hi all: > > > > 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. > >Try ?paste unstead of `c': paste(tenn$up, tenn$down, tenn$stable, sep = "") --sundar
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, are: with(tenn, 100 * up + 10 * down + stable) # numeric result with(tenn, interaction(up, down, stable, sep ="")) # factor result
"Doran, Harold" <HDoran at air.org> writes:> Hi all: > > > > 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).That's not contatenation!> I tried c(tenn$up,tenn$down,tenn$stable)but this is....> But this isn't working. Thanks for any help offered.It's working alright, just not doing what you want. How about paste(tenn$up,tenn$down,tenn$stable,sep="") ? -- 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