Re: [R] strsplit

From: Sarah Goslee <>
Date: Tue, 01 Jun 2010 10:05:36 -0400

How about this:

testdata <- data.frame(sp = c("GenusA_SpeciesC_Tree", "GenusA_SpeciesF_Tree", "GenusB_SpeciesA_Shrub"), stringsAsFactors=FALSE)

# for one
unlist(strsplit(testdata[1,1], split="_"))

# for all of them, sapply(testdata[,1], strsplit, split="_"))


On Tue, Jun 1, 2010 at 5:45 AM, JoŽl Baumann <> wrote:
> Hello!
> I have the following problem:
> I have a file in R that has in the first row three informations in one row
> that I would like to in three different rows.
> The first row looks like this:
> GenusA_SpeciesC_Tree
> GenusA_SpeciesF_Tree
> GenusB_SpeciesA_Shrub
> ...
> I tried with strsplit and and substring but I don't get any solution. I know
> I can do this in Excel, but in R would be much nicer!

Sarah Goslee

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 01 Jun 2010 - 14:10:17 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 01 Jun 2010 - 14:20:25 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive