Re: [R] Getting multiple tables when using table(dataframe) to tabulate data

From: jim holtman <jholtman_at_gmail.com>
Date: Thu, 28 Feb 2008 20:48:28 -0500

Is this what you want?

> tapply(x$count, list(x$delta_ts, x$status), sum)

           ASSIGNED CLOSED NEW RESOLVED
2008-02-21        2     NA   2        0
2008-02-22        0      0   6        1
2008-02-23        2      1  12        0
2008-02-24        7      4  16        2
2008-02-25        2      6  22        5
2008-02-26        6      8  38        3
2008-02-27       NA      3  56        5
2008-02-28       NA      3  56        5


On Thu, Feb 28, 2008 at 8:22 PM, obradoa <aobradovic_at_gmail.com> wrote:
>
> I am having hard time tabulating data in a dataframe, and getting a single
> "table" for an answer. I am trying to tabulate all "counts" for given
> "status" on a given date.
>
>
> I have a data frame such as:
>
>
> delta_ts status count
> 1 2008-02-27 CLOSED 3
> 2 2008-02-27 NEW 56
> 3 2008-02-27 RESOLVED 5
> 4 2008-02-21 ASSIGNED 1
> 5 2008-02-21 ASSIGNED 1
> 6 2008-02-21 NEW 2
> 7 2008-02-21 RESOLVED 0
> 8 2008-02-22 ASSIGNED 0
> 9 2008-02-22 CLOSED 0
> 10 2008-02-22 NEW 6
> 11 2008-02-22 RESOLVED 1
> 12 2008-02-23 ASSIGNED 2
> 13 2008-02-23 CLOSED 1
> 14 2008-02-23 NEW 12
> 15 2008-02-23 RESOLVED 0
> 16 2008-02-24 ASSIGNED 7
> 17 2008-02-24 CLOSED 4
> 18 2008-02-24 NEW 16
> 19 2008-02-24 RESOLVED 2
> 20 2008-02-25 ASSIGNED 2
> 21 2008-02-25 CLOSED 6
> 22 2008-02-25 NEW 22
> 23 2008-02-25 RESOLVED 5
> 24 2008-02-26 ASSIGNED 6
> 25 2008-02-26 CLOSED 8
> 26 2008-02-26 NEW 38
> 27 2008-02-26 RESOLVED 3
> 28 2008-02-28 CLOSED 3
> 29 2008-02-28 NEW 56
> 30 2008-02-28 RESOLVED 5
>
>
> When I do "table" on that frame I get a long list that looks like this:
>
>
> > table(data)
> , , count = 0
>
> status
> delta_ts ASSIGNED CLOSED NEW RESOLVED
> 2008-02-21 0 0 0 1
> 2008-02-22 1 1 0 0
> 2008-02-23 0 0 0 1
> 2008-02-24 0 0 0 0
> 2008-02-25 0 0 0 0
> 2008-02-26 0 0 0 0
> 2008-02-27 0 0 0 0
> 2008-02-28 0 0 0 0
>
>
> and so on all the way up to
>
> , , count = 56
>
> status
> delta_ts ASSIGNED CLOSED NEW RESOLVED
> 2008-02-21 0 0 0 0
> 2008-02-22 0 0 0 0
> 2008-02-23 0 0 0 0
> 2008-02-24 0 0 0 0
> 2008-02-25 0 0 0 0
> 2008-02-26 0 0 0 0
> 2008-02-27 0 0 1 0
> 2008-02-28 0 0 1 0
>
>
>
> What I actually want is for my counts to be properly tabulated in one single
> table that looks something like this.
>
>
> delta_ts ASSIGNED CLOSED NEW RESOLVED
> 2008-02-21 2 5 9 15
>
> and so on...
>
>
> Any ideas what I am doing wrong?
>
> Thanks!
> --
> View this message in context: http://www.nabble.com/Getting-multiple-tables-when-using-table%28dataframe%29-to-tabulate-data-tp15750098p15750098.html
> Sent from the R help mailing list archive at Nabble.com.
>
> [[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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?  Tell me what you want to
do, not how you want to do it.

______________________________________________
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 Fri 29 Feb 2008 - 01:57:37 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 Fri 29 Feb 2008 - 02:30:17 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