[R] Getting multiple tables when using table(dataframe) to tabulate data
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Feb 29 03:09:07 CET 2008
Try this:
xtabs(count ~., data)
Also look at ?ftable, ?prop.table, ?reshape and the reshape package.
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.
>
More information about the R-help
mailing list