Re: [R] generic pasting of strings

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.be>
Date: Tue 31 Oct 2006 - 11:54:15 GMT

try something like:

apply(tmp1[, ncol(tmp1):1], 1, paste, sep = ">")

I hope it helps.

Best,
Dimitris



Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium

Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


> Hi there,
>
> is there a way to make the following code generic, so that i can
> paste()
> the columns in tmp1 depending on the dimensions given in embed()?
>
>> tmp1 <- embed(as.vector(shrinkTable$AOIname), dimension = 2);
>> tmp1
> [,1] [,2]
> [1,] "AOI4" "AOI1"
> [2,] "AOI6" "AOI4"
> [3,] "AOI4" "AOI6"
>> tmp2 <- paste(tmp1[, 2], tmp1[, 1], sep = ">");
>> tmp2

> [1] "AOI1>AOI4" "AOI4>AOI6" "AOI6>AOI4"
>
> for dimension = 3 this would look like this:
>
>> tmp1 <- embed(as.vector(shrinkTable$AOIname), dimension = 3);
>> tmp1
> [,1] [,2] [,3]
> [1,] "AOI6" "AOI4" "AOI1"
> [2,] "AOI4" "AOI6" "AOI4"
>> tmp2 <- paste(tmp1[ ,3], tmp1[, 2], tmp1[, 1], sep = ">");
>> tmp2

> [1] "AOI1>AOI4>AOI6" "AOI4>AOI6>AOI4"
>
> Any ideas?
>
> Thanks for your help,
>
>
> Robert Lischke
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



R-help@stat.math.ethz.ch 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. Received on Tue Oct 31 23:01:48 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 31 Oct 2006 - 12:30:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.