[R] converting a numeric vector to a single string

Hadley Wickham h.wickham at auckland.ac.nz
Wed Nov 19 02:48:32 CET 2003


Did you read ?paste ?  I think using the collapse argument will give you 
what you want.

Hadley

Rajarshi Guha wrote:

>Hi,
>  this is probably a very obvious question but I cant see how I can
>convert a numeric vector to a single string as opposed to  a character
>vector.
>
>Essentially if I have a vector defined as
>
>x <- c(1,2,3.76,4.56)
>
>I would like to generate the string:
>
>"1 2 3.76 4.56"
>
>rather than
>
>"1" "2" "3.76" "4.56"
>
>which is what paste() gives me.
>
>I thought of using a textConnection() but as far as I can see I need to
>use something like writeLines which requires a character vector.
>
>Thanks,
>
>  
>




More information about the R-help mailing list