[R] coercing columns

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Fri Jan 7 17:38:42 CET 2005



Christoph Scherber wrote:

> Dear all,
> 
> I have a data frame that looks like this:
> 
> c1   c2   c3
> A    B    C
> B    C    A
> A    A    B
> 
> and so on;
> 
> I´d like to produce one single vector consisting of the columns c1,c2, 
> c3, such that
> 
> vector=("A","B","A","B","C","A","C","A","B")
> 
> I guess it´s easy to do but I don´t know how...Can anyone help me?
> 

Christoph,

Assuming c1, c2, and c3 are stored as factor and `x' is your data.frame, 
then you can do:

unlist(lapply(x, as.character))

Otherwise if c1, c2, and c3 are already character then you can skip the 
lapply part and just do unlist.

--sundar




More information about the R-help mailing list