OPPS^2!! Did it again. The version given below now does seem to work properly: last line now changed (yet again) to
A$Count <- as.numeric(levels(A$Count)[unclass(A$Count)]) On 04-Nov-09 21:47:32, Ted Harding wrote: > OOPS! Sorry, I made an oversight in the code I posted just now > (and I didn't check the result carefullt enough ... ). a <- matrix(c('genusA speciesA', 10, 'genusB speciesAA', 20, 'genusC speciesAAA subspeciesA', 15, 'genusC speciesAAA subspeciesB', 25), nrow=4, byrow=TRUE) a # [,1] [,2] # [1,] "genusA speciesA" "10" # [2,] "genusB speciesAA" "20" # [3,] "genusC speciesAAA subspeciesA" "15" # [4,] "genusC speciesAAA subspeciesB" "25" A <- NULL for( i in (1:nrow(a))){ Names <- unlist(strsplit(a[i,1],"[ ]+")) if(length(Names)==2) Names <- c(Names,"no.subspecies") A <- rbind(A,c(Names,a[i,2])) } colnames(A) <- c("Genus","Species","Subspecies","Count") A <- as.data.frame(A) A$Count <- as.numeric(levels(A$Count)[unclass(A$Count)]) A # 1 genusA speciesA no.subspecies 10 # 2 genusB speciesAA no.subspecies 20 # 3 genusC speciesAAA subspeciesA 15 # 4 genusC speciesAAA subspeciesB 25 Ted [I plead hypocaffeinaemia] -------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.hard...@manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 04-Nov-09 Time: 22:15:50 ------------------------------ XFMail ------------------------------ ______________________________________________ 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.