[R] merging two vectors

Duncan Murdoch murdoch.duncan at gmail.com
Sun Dec 5 16:14:59 CET 2010


On 05/12/2010 9:57 AM, ram basnet wrote:
> Dear R users,
>
> It may be very simple but it is being difficult for me.
> I have two vectors with some common string. And, i want to combine into a vector in such a way that it includes string from both vectors and make a unique.
>
> For example:
>
> x<- paste(rep("A",5),1:5,sep = ".")
> x
> [1] "A.1" "A.2" "A.3" "A.4" "A.5"
>
> y<- paste(rep("A"),3:7, sep = ".")
> y
> [1] "A.3" "A.4" "A.5" "A.6" "A.7"
>
> Now, I want to combine these two vectors in the following way:
>
> "A.1" "A.2" "A.3" "A.4" "A.5"  "A.6" "A.7"
>
> I tried with merge(), but not able to get as I want.
>
> Is there any way to do this in R ?

unique(c(x,y))

Duncan Murdoch



More information about the R-help mailing list