[R] merge strings
bingshanli at yahoo.com
Mon Sep 18 04:16:51 CEST 2006
Hi Duncan Murdoch,
Thanks for the trick and it works!
--- Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
> Bingshan Li wrote:
> > Hi all,
> > I have a vector and want to merge its elements one
> > one into a single string or number. For example,
> > x=c(1,2,3), what I want is a new number 123. I
> > "paste" but it just output "1" "2" "3" which is
> > what I want. Is there any way to do this?
> > Thanks!
> Use the collapse argument to paste:
> paste(x, collapse="")
> Or, if you want a number,
> sum(x * 10^rev(1:length(x) - 1))
> Duncan Murdoch
More information about the R-help