Try something like: > mytable <- table(known, modelout) > prop.table( mytable, 1 )
Also look at ?addmargins and the CrossTable function in the gmodels package. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Scott Bearer > Sent: Thursday, July 12, 2007 11:32 AM > To: [email protected] > Subject: [R] calculating percent error from 2 vectors > > Hello, > > I believe this is an easy scripting problem, but one I am > stumbling on. > > I have a "known" vector of 3 colors with nrow=10: > known<-c("red", "blue", "red", "red", "yellow", "blue", > "yellow", "blue", "blue", "yellow") > > and a model output vector: > modelout<-c("red", "red", "red", "blue", "yellow", "blue", > "blue", "red", "blue", "yellow") > > I would like to determine the proportion (in)correctly > identified for each color. In other words: > % correct "red"= > % correct "blue"= > % correct "yellow"= > > How would I code this (assuming the actual dataset is more complex)? > > Any help would be much appreciated. > > Thank you, > Scott > > ______________________________________________ > [email protected] 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. > ______________________________________________ [email protected] 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.
