I have a list of scientific names in a data set. I would like to split the names into genus, species and subspecies. Not all names include a subspecies. Could someone show me how to do this?
My example code is: a <- matrix(c('genusA speciesA', 10, 'genusB speciesAA', 20, 'genusC speciesAAA subspeciesA', 15, 'genusC speciesAAA subspeciesB', 25), nrow=4, byrow=TRUE) aa <- data.frame(a) colnames(aa) <- c('species', 'counts') aa # The code returns species counts 1 genusA speciesA 10 2 genusB speciesAA 20 3 genusC speciesAAA subspeciesA 15 4 genusC speciesAAA subspeciesB 25 # I would like there to be 4 columns as below genus species subspecies counts genusA speciesA no.subspecies 10 genusB speciesAA no.subspecies 20 genusC speciesAAA subspeciesA 15 genusC speciesAAA subspeciesB 25 I have tried using 'strsplit', but cannot get the desired result. Thank you for any help with this. Mark Miller Gainesville, Florida -- View this message in context: http://old.nabble.com/splitting-scientific-names-into-genus%2C-species%2C-and-subspecies-tp26204666p26204666.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@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.