Re: [R] concatenating range of columns in dataframe

2017-03-10 Thread Evan Cooch
On 3/10/2017 2:24 AM, Ulrik Stervbo wrote: Hi Evan, the unite function of the tidyr package achieves the same as Jim suggested, but in perhaps a slightly more readable manner. Ulrik I use perl for scripting, so readability isn't a big factor. ;-) Thanks! ___

Re: [R] concatenating range of columns in dataframe

2017-03-10 Thread Evan Cooch
On 3/10/2017 1:48 AM, Jim Lemon wrote: Hi Evan, How about this: df2<-data.frame(Trt=df[,1],Conc=apply(df[,2:5],1,paste,sep="",collapse="")) Jim Thanks! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/m

Re: [R] concatenating range of columns in dataframe

2017-03-10 Thread Evan Cooch
On 3/10/2017 2:23 AM, Bert Gunter wrote: I think you need to spend some time with an R tutorial or two, especially with regard to indexing. Unless I have misunderstood (apologies if I have), df$Conc <- apply(df[,-1],1,paste,collapse="") does it. -- Bert \ Thanks -- sage advice. ___

Re: [R] concatenating range of columns in dataframe

2017-03-09 Thread Ulrik Stervbo
Hi Evan, the unite function of the tidyr package achieves the same as Jim suggested, but in perhaps a slightly more readable manner. Ulrik On Fri, 10 Mar 2017 at 07:50 Jim Lemon wrote: > Hi Evan, > How about this: > > df2<-data.frame(Trt=df[,1],Conc=apply(df[,2:5],1,paste,sep="",collapse=""))

Re: [R] concatenating range of columns in dataframe

2017-03-09 Thread Bert Gunter
I think you need to spend some time with an R tutorial or two, especially with regard to indexing. Unless I have misunderstood (apologies if I have), df$Conc <- apply(df[,-1],1,paste,collapse="") does it. -- Bert Bert Gunter "The trouble with having an open mind is that people keep coming al

Re: [R] concatenating range of columns in dataframe

2017-03-09 Thread Jim Lemon
Hi Evan, How about this: df2<-data.frame(Trt=df[,1],Conc=apply(df[,2:5],1,paste,sep="",collapse="")) Jim On Fri, Mar 10, 2017 at 3:16 PM, Evan Cooch wrote: > Suppose I have the following data frame (call it df): > > Trt y1 y2 y3 y4 > A1A 1001 > A1B 1100 > A1 C

[R] concatenating range of columns in dataframe

2017-03-09 Thread Evan Cooch
Suppose I have the following data frame (call it df): Trt y1 y2 y3 y4 A1A 1001 A1B 1100 A1 C 0 10 1 A1D 111 1 What I want to do is concatenate columns y1 -> y4 into a contiguous string (which I'll call df$conc), so that the final df looks l