[R] probably simple paste question

Gavin Simpson gavin.simpson at ucl.ac.uk
Fri May 29 19:47:11 CEST 2009


On Fri, 2009-05-29 at 12:39 -0500, Erin Hodgess wrote:
> Dear R People:
> 
> I have the following vector and am using the paste command:
> 
> > ya
> [1] 57  2  8
> > paste("stuff",ya,sep=" ")
> [1] "stuff 57" "stuff 2"  "stuff 8"
> 
> What I want to have is
> "stuff 57 2 8"
> 
> 
> I also tried:
> > yb <- paste(cat("stuff",ya))
> stuff 57 2 8> yb
> character(0)
> 
> I have the feeling that it's really simple and right in front of me.

You need (or rather, "one way is") to collapse the 'ya'

> paste("stuff", paste(ya, collapse = " "))
[1] "stuff 57 2 8"

HTH

G

> 
> Thanks,
> Erin
> 
> 
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090529/40aff201/attachment-0002.bin>


More information about the R-help mailing list