Re: [R] strsplit

From: Sarah Goslee <sarah.goslee_at_gmail.com>
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
do.call(rbind, sapply(testdata[,1], strsplit, split="_"))

Sarah

On Tue, Jun 1, 2010 at 5:45 AM, JoŽl Baumann <joelbaumann_at_gmx.net> 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
http://www.functionaldiversity.org

______________________________________________
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.
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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive