[R] Conditional Selection of Columns for Tables

From: Mark Hempelmann <neo27_at_rakers.de>
Date: Sat 27 Jan 2007 - 19:31:43 GMT


Dear Wizards -

        Thank you so much for your help. That was exactly what I was looking for. Now, I have been working on conditional selection of columns in a data frame. My goal is to calculate the total revenue per sales representative per status in a table. I have come to a complete stop:

Let's say, we have a data.frame called df with several columns and a number of rows:

df <- data.frame( nr=101:110, letter=LETTERS[1:10], name=c(rep("eenie",3), rep("meenie",2), rep("miney",4),

   "moe"), revenue=round(runif(10, min=100, max=1000),0), status=round(runif(10,min=1, max=3),0) )

gives

     nr letter   name revenue status
1  101      A  eenie     764      2
2  102      B  eenie     918      2
3  103      C  eenie     936      3
4  104      D meenie     770      2
5  105      E meenie     280      1
6  106      F  miney     172      2
7  107      G  miney     439      2
8  108      H  miney     607      1
9  109      I  miney     553      1
10 110      J    moe     322      2

where status means: 3=no deal, 2=pending, 1=good job. now, we want the total revenue per sales representative per status in a table.

sum( subset(df, name=="eenie", select=revenue) )

gives the total of eenie without status, but I would like to have sthg like:

status
1
name revenue
eenie 1000
meenie 2000...

status
2
name revenue
eenie 100
meenie 200...

Are these flat contingency tables? How can I get the results without much hazzle in one list/ table? i did read the ?ftable and what I was able to derive so far is:

flat.df <- ftable(df[c("name", "revenue", "status")])

but I am unable to further agglomerate the data. hmpf. Good God, what would I do without my R-help forum?

Thank you again
Cheers and a relaxing weekend
mark



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 Jan 28 06:42:32 2007

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 Sat 27 Jan 2007 - 23:30:30 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.