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.
On Jul 17, 2009, at 5:47 AM, Miroslav Nikolov wrote:> > 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.Several options are available. An example dataset would have made understanding your setup much clearer. I am having trouble parsing your natural language presentation of the problem. Perhaps these examples will help: > y <- data.frame(x=sample(LETTERS[1:5], 20, replace=TRUE) ) > table(y$x) A B C D E 3 5 2 7 3 > xtabs(~x, data=y) x A B C D E 3 5 2 7 3 > ?tapply > tapply(y$x, y$x, length) A B C D E 3 5 2 7 3 Pie charts are deprecated on this list, so it's not surprising you have difficulty finding examples, but surely you can find worked examples, nonetheless. The search sites to consult include: http://search.r-project.org/nmz.html http://addictedtor.free.fr/graphiques/ -- David Winsemius, MD Heritage Laboratories West Hartford, CT
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