I have a vector that looks like this:> foo[1] "o" "o" "o" "x" "o" "o" "o" "o" "o" "x" "x" "o" "x How can we find the percentage of "o" and "x" in that vector in R? - G.V
On Wed, Sep 29, 2010 at 6:43 PM, Gundala Viswanath <gundalav at gmail.com> wrote:> I have a vector that looks like this: > >> foo > [1] "o" "o" "o" "x" "o" "o" "o" "o" "o" "x" "x" "o" "x > > How can we find the percentage of "o" and "x" in > that vector in R?table(foo)/length(foo) Peter
Try this: prop.table(table(foo)) On Wed, Sep 29, 2010 at 10:43 PM, Gundala Viswanath <gundalav@gmail.com>wrote:> I have a vector that looks like this: > > > foo > [1] "o" "o" "o" "x" "o" "o" "o" "o" "o" "x" "x" "o" "x > > How can we find the percentage of "o" and "x" in > that vector in R? > > - G.V > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
sum(foo=="o")/length(foo) -- View this message in context: http://r.789695.n4.nabble.com/How-to-get-a-proportion-of-a-Vector-Member-tp2720060p2720067.html Sent from the R help mailing list archive at Nabble.com.
Hi or prop.table(table(foo)) Regards Petr r-help-bounces at r-project.org napsal dne 30.09.2010 03:45:30:> On Wed, Sep 29, 2010 at 6:43 PM, Gundala Viswanath <gundalav at gmail.com>wrote:> > I have a vector that looks like this: > > > >> foo > > [1] "o" "o" "o" "x" "o" "o" "o" "o" "o" "x" "x" "o" "x > > > > How can we find the percentage of "o" and "x" in > > that vector in R? > > > table(foo)/length(foo) > > Peter > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.