Re: [R] merging two vectors

2010-12-05 Thread David Winsemius


On Dec 5, 2010, at 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.


?union

--

David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] merging two vectors

2010-12-05 Thread Santosh Srinivas
unique(c(x,y))

On Sun, Dec 5, 2010 at 8:27 PM, 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 ?
>
> If it is, it will be great.
> Thanks in advance.
>
> Regards,
> Ram Kumar Basnet.
> Wageningen, Netherland.
>
>
>
>        [[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] merging two vectors

2010-12-05 Thread Duncan Murdoch

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] merging two vectors

2010-12-05 Thread ram basnet
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 ?
 
If it is, it will be great.
Thanks in advance.
 
Regards,
Ram Kumar Basnet.
Wageningen, Netherland.


  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] merging two vectors

2010-05-14 Thread Marc Schwartz
On May 14, 2010, at 7:22 AM, Knut Krueger wrote:

> Hi to all,
> 
> is there a better way instead for loop  to merge two vectors:
> 
> V1 <- c(1,3,5,7,9)
> V2<-  c(20,40,60,80,100)
> to
> V_merged <- c(1,20,3,40,5,60,7,80,9,100)
> 
> Kind regards
> Knut

Try this:

> as.vector(rbind(V1, V2))
 [1]   1  20   3  40   5  60   7  80   9 100


This presumes that both vectors are of the same length.

HTH,

Marc Schwartz

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] merging two vectors

2010-05-14 Thread Knut Krueger

Hi to all,

is there a better way instead for loop  to merge two vectors:

V1 <- c(1,3,5,7,9)
V2<-  c(20,40,60,80,100)
to
V_merged <- c(1,20,3,40,5,60,7,80,9,100)

Kind regards
Knut

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.