[R] Joining variables

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Wed May 24 20:53:05 CEST 2006



Guenther, Cameron wrote:
> Hello,
> 
> If I have two variables that are factors or characters and I want to
> create a new variable that is the combination of both what function can
> I use to accomplish this?
> 
> Ex.
> 
> Var1			Var2
> SA100055113		19851113
> 
> And I want
> 
> NewVar
> SA10005511319851113
> 
> Thanks in advance.

See ?paste or ?sprintf

Var1 <- factor("SA100055113")
Var2 <- 19851113

NewVar <- paste(Var1, Var2, sep = "")
NewVar <- sprintf("%s%s", Var1, Var2)

HTH,

--sundar



More information about the R-help mailing list