[R] string concatenate across rows of a matrix??

Tony Plate tplate at blackmesacapital.com
Tue Sep 24 22:13:25 CEST 2002


 > apply(format(x2), 1, paste, collapse=" ")
       1       2       3       4
"a 1 k" "b 2 l" "c 3 m" "d 4 n"


At 12:45 PM 9/24/2002 -0700, Albert Kim wrote:

>Is there a simple way to string-concatenate across the rows of a matrix or
>data.frame into a vector of strings?  perhaps using paste() or
>something like it?
>
>That is, I want to map from something like x2 below:
>
>         > x2 <- data.frame(C1 = letters[1:4], C3=1:4, C3=letters[11:14])
>         > x2
>           C1 C3 C3
>         1  a  1  k
>         2  b  2  l
>         3  c  3  m
>         4  d  4  n
>
>to something like:
>
>         [1]  "a  1  k"
>         [2]  "b  2  l"
>         [3]  "c  3  m"
>         [4]  "d  4  n"
>
>Sincerely,
>Al Kim
>Research Scientist
>Department of Psychology
>University of Washington, Box 351525
>Seattle, WA. 98195, USA
>E-Mail:  alkim at u.washington.edu;  Tel: (206)543-2395
>
>
>
>-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
>r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
>Send "info", "help", or "[un]subscribe"
>(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
>_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ 
>

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list