1

I cannot get my head around gsub(). If text is:

 text <- "Genus_species_1652_NL"

How would I extract to get

"Genus species"

Thanks. This is a useful link but I havnt been able to sort it http://biostat.mc.vanderbilt.edu/wiki/pub/Main/SvetlanaEdenRFiles/regExprTalk.pdf

4

1 に答える 1

3

You can do this like:

> gsub('([A-z]+)_([A-z]+)_.*', '\\1 \\2', text)
[1] "Genus species"

but as mentioned in a comment, a tool like strsplit may be more useful.

于 2013-02-05T21:45:21.120 に答える