[R] concatenating 2 text columns in a data.frame

Philipp Pagel p.pagel at wzw.tum.de
Mon Feb 2 16:01:18 CET 2009


On Mon, Feb 02, 2009 at 09:44:28AM -0500, Shaun Grannis wrote:
> I'm trying to concatenate values from two columns in a data frame. For  
> example, I have the following data.frame:
>
> C1  C2  C3  C4  C5
> A   B   *F   C*   Q
> G   H   *I   J*   T
> K   D   *R   S*   E
> P   L   *M   N*   O
>
> I'd like to concatenate text from columns C3 and C4, to yield either a  
> list or vector, like so:
>
> NewCol
>  FC
>  IJ
>  RS
>  MN

assuming your data frame is named foo:

foo$NewCol <- paste(foo$C3, foo$C4, sep='')

cu
	Philipp

-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
http://mips.gsf.de/staff/pagel




More information about the R-help mailing list