[R] string concatenate across rows of a matrix??
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Tue Sep 24 22:36:56 CEST 2002
Tony Plate <tplate at blackmesacapital.com> writes:
> > apply(format(x2), 1, paste, collapse=" ")
> 1 2 3 4
> "a 1 k" "b 2 l" "c 3 m" "d 4 n"
...or even (data frames only):
> do.call("paste",x2)
[1] "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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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