[R] easy way of paste

Sarah Goslee sarah.goslee at gmail.com
Thu Mar 21 16:20:40 CET 2013


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.yuan at 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



More information about the R-help mailing list