Re: [R] using "table" in R

From: jim holtman <jholtman_at_gmail.com>
Date: Sun 17 Sep 2006 - 03:09:03 GMT

Here is one way; you create a vector of the data in the dataframe with 'unlist' and then use table:

> d = as.data.frame(matrix(c(1, 2, 3, 3), 2,2))
> d
  V1 V2
1 1 3
2 2 3
> table(unlist(d))

1 2 3
1 1 2
>

On 9/16/06, Bingshan Li <bingshanli@yahoo.com> wrote:
> Hi there,
>
> I have a dataframe whose elements are numbers or
> characters. I want to extract the frequencies of each
> elements in the dataframe. For example,
>
> d = as.data.frame(matrix(c(1, 2, 3, 3), 2,2))
>
> What I want is first what are the elements in the data
> (1,2,3 here) and second what are their frequencies
> (1,1,2 respectively). How to use "table" to extract
> these two pieces of information? I played with "table"
> but couldn't extract the information. Please assume
> that we do not know how many elements in the dataframe
> a priori.
>
> Thanks a lot!
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
R-help@stat.math.ethz.ch 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.
Received on Sun Sep 17 13:12:40 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 17 Sep 2006 - 04:30:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.