Quantcast

How to get a proportion of a Vector Member

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to get a proportion of a Vector Member

Gundala Viswanath
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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to get a proportion of a Vector Member

plangfelder
On Wed, Sep 29, 2010 at 6:43 PM, Gundala Viswanath <[hidden email]> 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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to get a proportion of a Vector Member

Henrique Dallazuanna
In reply to this post by Gundala Viswanath
Try this:

 prop.table(table(foo))

On Wed, Sep 29, 2010 at 10:43 PM, Gundala Viswanath <[hidden email]>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
>
> ______________________________________________
> [hidden email] 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]]


______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to get a proportion of a Vector Member

Peng, C
In reply to this post by Gundala Viswanath
sum(foo=="o")/length(foo)

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to get a proportion of a Vector Member

PIKAL Petr
In reply to this post by plangfelder
Hi
or

prop.table(table(foo))

Regards
Petr

[hidden email] napsal dne 30.09.2010 03:45:30:

> On Wed, Sep 29, 2010 at 6:43 PM, Gundala Viswanath <[hidden email]>
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
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Loading...