[R] easy way of paste

2013-03-21 Thread Yuan, Rebecca
Hello,

Is there a better way to use paste such as:

a = 
paste(colnames(list.indep)[1],colnames(list.indep)[2],colnames(list.indep)[3],colnames(list.indep)[4],colnames(list.indep)[5],sep=+)



 a

[1] aa+dummy1+dummy2+bb+cc



I tried



a = paste(colnames(list.indep)[1:5],sep=+)



 a

[1] aa dummy1 dummy2  bb   cc

But it will not give me the way I want.

Thanks,

Rebecca


--
This message, and any attachments, is for the intended r...{{dropped:5}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] easy way of paste

2013-03-21 Thread Sarah Goslee
It looks like you want collapse rather than sep:

 list.indep - data.frame(aa=1:4, dummy1=1:4, dummy2=1:4, bb=1:4, cc=1:4)
 paste(colnames(list.indep), collapse=+)
[1] aa+dummy1+dummy2+bb+cc

On Thu, Mar 21, 2013 at 11:15 AM, Yuan, Rebecca
rebecca.y...@bankofamerica.com wrote:
 Hello,

 Is there a better way to use paste such as:

 a = 
 paste(colnames(list.indep)[1],colnames(list.indep)[2],colnames(list.indep)[3],colnames(list.indep)[4],colnames(list.indep)[5],sep=+)



 a

 [1] aa+dummy1+dummy2+bb+cc



 I tried



 a = paste(colnames(list.indep)[1:5],sep=+)



 a

 [1] aa dummy1 dummy2  bb   
 cc

 But it will not give me the way I want.

 Thanks,

 Rebecca




--
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] easy way of paste

2013-03-21 Thread arun
 dat2-as.data.frame(matrix(1:20,ncol=5))
 colnames(dat2)- c(aa,dummy1,dummy2,bb,cc)
 paste(colnames(dat2),collapse=+)
#[1] aa+dummy1+dummy2+bb+cc
A.K.



- Original Message -
From: Yuan, Rebecca rebecca.y...@bankofamerica.com
To: R help r-help@r-project.org
Cc: 
Sent: Thursday, March 21, 2013 11:15 AM
Subject: [R] easy way of paste

Hello,

Is there a better way to use paste such as:

a = 
paste(colnames(list.indep)[1],colnames(list.indep)[2],colnames(list.indep)[3],colnames(list.indep)[4],colnames(list.indep)[5],sep=+)



 a

[1] aa+dummy1+dummy2+bb+cc



I tried



a = paste(colnames(list.indep)[1:5],sep=+)



 a

[1] aa dummy1             dummy2              bb                   cc

But it will not give me the way I want.

Thanks,

Rebecca


--
This message, and any attachments, is for the intended r...{{dropped:5}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] easy way of paste

2013-03-21 Thread Yuan, Rebecca
Hello Sarah,

Yes, that is what I want.

Thanks!

Cheers,

Rebecca

-Original Message-
From: Sarah Goslee [mailto:sarah.gos...@gmail.com] 
Sent: Thursday, March 21, 2013 11:21 AM
To: Yuan, Rebecca
Cc: R help
Subject: Re: [R] easy way of paste

It looks like you want collapse rather than sep:

 list.indep - data.frame(aa=1:4, dummy1=1:4, dummy2=1:4, bb=1:4, 
 cc=1:4) paste(colnames(list.indep), collapse=+)
[1] aa+dummy1+dummy2+bb+cc

On Thu, Mar 21, 2013 at 11:15 AM, Yuan, Rebecca 
rebecca.y...@bankofamerica.com wrote:
 Hello,

 Is there a better way to use paste such as:

 a = 
 paste(colnames(list.indep)[1],colnames(list.indep)[2],colnames(list.in
 dep)[3],colnames(list.indep)[4],colnames(list.indep)[5],sep=+)



 a

 [1] aa+dummy1+dummy2+bb+cc



 I tried



 a = paste(colnames(list.indep)[1:5],sep=+)



 a

 [1] aa dummy1 dummy2  bb   
 cc

 But it will not give me the way I want.

 Thanks,

 Rebecca




--
Sarah Goslee
http://www.functionaldiversity.org

--
This message, and any attachments, is for the intended r...{{dropped:2}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] easy way of paste

2013-03-21 Thread Yuan, Rebecca
Hello A.K.,

Thanks! I use collapse instead of sep and get the answer.

Cheers,

Rebecca

-Original Message-
From: arun [mailto:smartpink...@yahoo.com] 
Sent: Thursday, March 21, 2013 11:21 AM
To: Yuan, Rebecca
Cc: R help
Subject: Re: [R] easy way of paste

 dat2-as.data.frame(matrix(1:20,ncol=5))
 colnames(dat2)- c(aa,dummy1,dummy2,bb,cc)
 paste(colnames(dat2),collapse=+)
#[1] aa+dummy1+dummy2+bb+cc
A.K.



- Original Message -
From: Yuan, Rebecca rebecca.y...@bankofamerica.com
To: R help r-help@r-project.org
Cc: 
Sent: Thursday, March 21, 2013 11:15 AM
Subject: [R] easy way of paste

Hello,

Is there a better way to use paste such as:

a = 
paste(colnames(list.indep)[1],colnames(list.indep)[2],colnames(list.indep)[3],colnames(list.indep)[4],colnames(list.indep)[5],sep=+)



 a

[1] aa+dummy1+dummy2+bb+cc



I tried



a = paste(colnames(list.indep)[1:5],sep=+)



 a

[1] aa dummy1             dummy2              bb                   cc

But it will not give me the way I want.

Thanks,

Rebecca


--
This message, and any attachments, is for the intended r...{{dropped:15}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.