[R] count each answer category in each column

Jim Lemon jim at bitwrit.com.au
Fri Apr 19 01:38:21 CEST 2013


On 04/19/2013 08:46 AM, Ye Lin wrote:
> Hey,
>
> Is it possible that R can calculate each options under each column and
> return a summary table?
>
> Suppose I have a table like this:
>
> Gender   Age   Rate
> Female    0-10   Good
> Male        0-10   Good
> Female     11-20  Bad
> Male         11-20  Bad
> Male>20     N/A
>
> I want to have a summary table including the information that how many
> answers in each category, sth like this:
>
>    X         Gender
> Male       3
> Female    2
> N/A        0
>
>    X          Age
> 0-10         2
> 11-20         2
>> 20           1
> N/A         0
>
> X          Rate
> Good       2
> Bad          2
> N/A         1
>
> So basically I want to calculate, in each column, how many people choose
> each answer, including N/A. I know I can do it in Excel in a very
> visualized way, but is there anyway to do it in R in a robust way if I have
> a fairly large dataset.
>
Hey Ye,
How about this?

yldat<-read.table(text="Gender   Age   Rate
Female    0-10   Good
Male        0-10   Good
Female     11-20  Bad
Male         11-20  Bad
Male         >20     N/A",header=TRUE)
require(prettyR)
describe(yldat)

Jim



More information about the R-help mailing list