[R] Count data categories from table

John Kane jrkrideau at yahoo.ca
Fri Jul 17 15:45:50 CEST 2009


aggregate?

Something like this should work although it is not very elegant.
================================================================
mydata <- data.frame(aa=rep(letters[1:10],2), bb=rnorm(20, 5,1))
ss <- aggregate(mydata[,2],list(aa=mydata$aa), sum)
pie(ss[,2])
================================================================
A more serious problem is that the results are going to be close to uninterpretable.  Pie charts just are not very good for this amount of data.  Have a look at the notes section of ?pie.
You might want to consider using a dot.chart.  


--- On Fri, 7/17/09, Miroslav Nikolov <miroslav.nikolov at abv.bg> wrote:

> From: Miroslav Nikolov <miroslav.nikolov at abv.bg>
> Subject: [R]  Count data categories from table
> To: r-help at r-project.org
> Received: Friday, July 17, 2009, 5:47 AM
> 
> Hi there,
> 
> I have a relatively simple question, though, I couldn't
> find a solution for
> it so far. I have a table with 1000 entries and columns
> containing
> information about different parameters for each entry.
> What I want to do is group all parameters from one of the
> columns [e.g. if
> all 1000 entries are grouped in 30 different categories
> (described as
> character strings) in a second column] and have a pie chart
> describing the
> distribution of all 1000 entries into these 30 categories.
> The problem I have is to make R count how many times each
> of the 30
> categories is present in the table; then if I have them
> counted (e.g. if I
> have category1 - 234 times,  category2 - 356 times,
> etc. in a vector/table)
> the rest will be easier.
> 
> Thanx for the help in advance!
> 
> Best,
> Miro
> -- 
> View this message in context: http://www.nabble.com/Count-data-categories-from-table-tp24531524p24531524.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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.
> 


      __________________________________________________________________
Ask a question on any topic and get answers from real people. Go to Yahoo! Answers and share what you know at http://ca.answers.yahoo.com




More information about the R-help mailing list