Re: [R] counting values in multiple columns

From: Tal Galili <tal.galili_at_gmail.com>
Date: Wed, 20 Apr 2011 10:14:21 +0300

Hi Yosub,
Here is one way it can be done (assuming I got you right):

# invent data
set.seed(24)
tbl <- matrix(sample(c("", letters[1:4]), 20*8, replace = T), 20,8)

# getting the number of codes for all years: table(c(tbl))
# getting the number of codes per year:
apply(tbl,2,table)

----------------Contact
Details:-------------------------------------------------------
Contact me: Tal.Galili_at_gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English)

On Wed, Apr 20, 2011 at 6:05 AM, Yosub Jung <yosubjung_at_berkeley.edu> wrote:

> Hello,
>
> I have a table that has 2000 rows and 8 columns. The headings of columns
> are: yearjel.code.1jel.code.2jel.code.3jel.code.4jel.code.5jel.code.6
> jel.code.7.
> Under each column, there are either numbers or blank spaces corresponding
> to
> the given year.
> For instance, my 10th row is:1019838242824382609170
> I want to count how many times each code appears in total and how many
> times
> it appears in each year.
> I don't think I can use table function. What can I do?
>
>
> Sincerely,
> Yosub Jung.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_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.
>

        [[alternative HTML version deleted]]



R-help_at_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. Received on Wed 20 Apr 2011 - 07:17:53 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 20 Apr 2011 - 07:30:31 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.

list of date sections of archive