[R] Splitting up rows in a data frame

Ista Zahn istazahn at gmail.com
Wed Feb 3 21:32:57 CET 2010


There is a colsplit() function in the reshape package that will do
this very easily.

-Ista

On Thu, Feb 4, 2010 at 3:41 PM, Tom Wenseleers
<tom.wenseleers at bio.kuleuven.be> wrote:
> Dear all,
> I have the following data frame
> goannot=read.table(file="c:\ApisGOannot.txt",colClasses="character",header=TRUE,sep="\t")
>        GB_nr           evidence                            GO_list
> 1       GB18414-RA     apis                             0001507, 0003990,
> 0004104
> 2       GB10293-RA     apis                             0003676
> 3       GB12644-RA     apis                             0003677, 0000786,
> 0006334, 0005634
> 4       GB17142-RA     apis                             0003677, 0003899,
> 0006350
> 5       GB15064-RA     apis                             0003677, 0005515
>
> and I would like to split up each row in the data frame based on the ", "
> delimiter in the GO_list column. I.e. I would like to obtain
>        GB_nr           evidence                            GO_list
> 1       GB18414-RA     apis                             0001507
> 2       GB18414-RA     apis                             0003990
> 3       GB18414-RA     apis                             0004104
> 4       GB10293-RA     apis                             0003676
> 5       GB12644-RA     apis                             0003677
> 6       GB12644-RA     apis                             0000786
> 7       GB12644-RA     apis                             0006334
> 8       GB12644-RA     apis                             0005634
> ...
>
> I started to try to do this using strsplit, but I was thinking there might
> be more elegant ways to do this?
> Any advice would be much appreciated (I am new to R)!
>
> cheers,
> Tom
>
>
> Dr. T. Wenseleers
> Dept. of Biology
> Zoological Institute
> K.U.Leuven
> Naamsestraat 59
> B-3000 Leuven
> Belgium
> tel. +32 (0)16 32 39 64
> mobile +32 (0)472 40 45 96
> e-mail tom.wenseleers at bio.kuleuven.be
> web http://bio.kuleuven.be/ento/wenseleers/twenseleers.htm
>
> ______________________________________________
> R-help at 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.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org



More information about the R-help mailing list