Re: [R] Concatenating two vectors into one

2009-05-18 Thread Stavros Macrakis
If you want to concatenate the *vectors*, you need 'c', which will
also coerce the elements to a common type.

If you want to concatenate the corresponding *elements* of the
vectors, you need 'paste', which will coerce them to character
strings.

 -s


On 5/18/09, Henning Wildhagen  wrote:
> Dear users,
>
> a very simple question:
>
> Given two vectors x and y
>
> x<-as.character(c("A","B","C","D","E","F"))
> y<-as.factor(c("1","2","3","4","5","6"))
>
> i want to combine them into a single vector z as A1, B2, C3 and so on.
>
> z<-x*y is not working, i tried several others function, but did not get to
> the solution.
>
> Thanks for your help,
>
> Henning
>
>
> --
>
>
>   [[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] Concatenating two vectors into one

2009-05-18 Thread Simon Pickett

Sorry,

I saw the word concatenate and dived in. Andrew Dolmans solution works fine.

Simon.


- Original Message - 
From: "Linlin Yan" 

To: "Simon Pickett" 
Cc: "Henning Wildhagen" ; 
Sent: Monday, May 18, 2009 12:30 PM
Subject: Re: [R] Concatenating two vectors into one



It seems that "c(x,y)" is not correct:

z<-c(x,y)
z

[1] "A" "B" "C" "D" "E" "F" "1" "2" "3" "4" "5" "6"

On Mon, May 18, 2009 at 7:17 PM, Simon Pickett  
wrote:

z<-c(x,y)

cheers, Simon.


- Original Message - From: "Henning Wildhagen" 


To: 
Sent: Monday, May 18, 2009 12:09 PM
Subject: [R] Concatenating two vectors into one



Dear users,

a very simple question:

Given two vectors x and y

x<-as.character(c("A","B","C","D","E","F"))
y<-as.factor(c("1","2","3","4","5","6"))

i want to combine them into a single vector z as A1, B2, C3 and so on.

z<-x*y is not working, i tried several others function, but did not get 
to

the solution.

Thanks for your help,

Henning


--


[[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.





__
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] Concatenating two vectors into one

2009-05-18 Thread Linlin Yan
It seems that "c(x,y)" is not correct:
> z<-c(x,y)
> z
 [1] "A" "B" "C" "D" "E" "F" "1" "2" "3" "4" "5" "6"

On Mon, May 18, 2009 at 7:17 PM, Simon Pickett  wrote:
> z<-c(x,y)
>
> cheers, Simon.
>
>
> - Original Message - From: "Henning Wildhagen" 
> To: 
> Sent: Monday, May 18, 2009 12:09 PM
> Subject: [R] Concatenating two vectors into one
>
>
>> Dear users,
>>
>> a very simple question:
>>
>> Given two vectors x and y
>>
>> x<-as.character(c("A","B","C","D","E","F"))
>> y<-as.factor(c("1","2","3","4","5","6"))
>>
>> i want to combine them into a single vector z as A1, B2, C3 and so on.
>>
>> z<-x*y is not working, i tried several others function, but did not get to
>> the solution.
>>
>> Thanks for your help,
>>
>> Henning
>>
>>
>> --
>>
>>
>> [[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.
>

__
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] Concatenating two vectors into one

2009-05-18 Thread Uwe Ligges



Henning Wildhagen wrote:
Dear users, 

a very simple question: 


Given two vectors x and y

x<-as.character(c("A","B","C","D","E","F"))
y<-as.factor(c("1","2","3","4","5","6"))

i want to combine them into a single vector z as A1, B2, C3 and so on.

z<-x*y is not working, i tried several others function, but did not get to 
the solution.



Homework? Anyway, see ?paste.

Uwe Ligges



Thanks for your help,

Henning




__
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] Concatenating two vectors into one

2009-05-18 Thread Linlin Yan
> z <- paste(x, y, sep = '')
> z
[1] "A1" "B2" "C3" "D4" "E5" "F6"

On Mon, May 18, 2009 at 7:09 PM, Henning Wildhagen  wrote:
> Dear users,
>
> a very simple question:
>
> Given two vectors x and y
>
> x<-as.character(c("A","B","C","D","E","F"))
> y<-as.factor(c("1","2","3","4","5","6"))
>
> i want to combine them into a single vector z as A1, B2, C3 and so on.
>
> z<-x*y is not working, i tried several others function, but did not get to
> the solution.
>
> Thanks for your help,
>
> Henning
>
>
> --
>
>
>        [[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] Concatenating two vectors into one

2009-05-18 Thread Ted Harding
On 18-May-09 11:09:45, Henning Wildhagen wrote:
> Dear users, 
> a very simple question: 
> 
> Given two vectors x and y
> 
> x<-as.character(c("A","B","C","D","E","F"))
> y<-as.factor(c("1","2","3","4","5","6"))
> 
> i want to combine them into a single vector z as A1, B2, C3 and so on.
> 
> z<-x*y is not working, i tried several others function, but did not
> get to the solution.
> 
> Thanks for your help,
> Henning

And a very simple solution! Use paste():

  x<-as.character(c("A","B","C","D","E","F"))
  y<-as.factor(c("1","2","3","4","5","6"))
  paste(x,y)
  # [1] "A 1" "B 2" "C 3" "D 4" "E 5" "F 6"
  paste(x,y,sep="")
  # [1] "A1" "B2" "C3" "D4" "E5" "F6"

Ted.
PS: 'x*y' will attempt to perform a numerical multiplication.
This cannot work for character vectors.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 18-May-09   Time: 12:23:56
-- XFMail --

__
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] Concatenating two vectors into one

2009-05-18 Thread Tony Breyal
Something like this should work:

z<- paste(x,y, sep='')

HTH,
Tony

On 18 May, 12:09, "Henning Wildhagen"  wrote:
> Dear users,
>
> a very simple question:
>
> Given two vectors x and y
>
> x<-as.character(c("A","B","C","D","E","F"))
> y<-as.factor(c("1","2","3","4","5","6"))
>
> i want to combine them into a single vector z as A1, B2, C3 and so on.
>
> z<-x*y is not working, i tried several others function, but did not get to
> the solution.
>
> Thanks for your help,
>
> Henning
>
> --
>
>         [[alternative HTML version deleted]]
>
> __
> r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://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] Concatenating two vectors into one

2009-05-18 Thread Andrew Dolman
 x<-as.character(c("A","B","C","D","E","F"))
 y<-as.factor(c("1","2","3","4","5","6"))

 ?paste
 paste(x,y, sep="")


andydol...@gmail.com


2009/5/18 Henning Wildhagen 

> Dear users,
>
> a very simple question:
>
> Given two vectors x and y
>
> x<-as.character(c("A","B","C","D","E","F"))
> y<-as.factor(c("1","2","3","4","5","6"))
>
> i want to combine them into a single vector z as A1, B2, C3 and so on.
>
> z<-x*y is not working, i tried several others function, but did not get to
> the solution.
>
> Thanks for your help,
>
> Henning
>
>
> --
>
>
>[[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.
>

[[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] Concatenating two vectors into one

2009-05-18 Thread Simon Pickett

z<-c(x,y)

cheers, Simon.


- Original Message - 
From: "Henning Wildhagen" 

To: 
Sent: Monday, May 18, 2009 12:09 PM
Subject: [R] Concatenating two vectors into one



Dear users,

a very simple question:

Given two vectors x and y

x<-as.character(c("A","B","C","D","E","F"))
y<-as.factor(c("1","2","3","4","5","6"))

i want to combine them into a single vector z as A1, B2, C3 and so on.

z<-x*y is not working, i tried several others function, but did not get to
the solution.

Thanks for your help,

Henning


--


[[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.


[R] Concatenating two vectors into one

2009-05-18 Thread Henning Wildhagen
Dear users, 

a very simple question: 

Given two vectors x and y

x<-as.character(c("A","B","C","D","E","F"))
y<-as.factor(c("1","2","3","4","5","6"))

i want to combine them into a single vector z as A1, B2, C3 and so on.

z<-x*y is not working, i tried several others function, but did not get to 
the solution.

Thanks for your help,

Henning


-- 


[[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.