I have data like this:
> head(df)
Date IsWin
20 2014-07-13 00:00:00 True
21 2014-08-01 00:00:00 True
22 2014-08-05 00:00:00 False
23 2014-06-28 00:00:00 True
24 2014-05-31 00:00:00 True
25 2014-06-06 00:00:00 True
I would like to group by Date and sum by IsWin (which should be a factor of 1 or -1).
I have read through this but it doesn't really deal with factors, so I don't know how to apply it How to group a data.frame by date?
Ultimately, I would like to pass the grouped and summed data to a bar chart to show the number of wins or losses, something like ggplot2 and a Stacked Bar Chart with Negative Values
The following outputs a table which is quite helpful to seeing what I want; however, I would like to translate this into a bar chart for better visuals:
> table(df[,1],df[,2])
False True
2014-05-25 00:00:00 1 0
2014-05-29 00:00:00 1 0
2014-05-30 00:00:00 2 0
2014-05-31 00:00:00 0 1
2014-06-06 00:00:00 0 1
2014-06-13 00:00:00 1 0
2014-06-14 00:00:00 0 1
2014-06-18 00:00:00 1 0
2014-06-19 00:00:00 0 1
2014-06-23 00:00:00 1 0
2014-06-24 00:00:00 1 0
2014-06-25 00:00:00 1 0
2014-06-27 00:00:00 0 1
2014-06-28 00:00:00 1 2
2014-07-02 00:00:00 1 0
2014-07-11 00:00:00 1 0
2014-07-13 00:00:00 0 2
2014-07-31 00:00:00 0 1
2014-08-01 00:00:00 0 1
2014-08-05 00:00:00 1 0
2014-08-07 00:00:00 1 0
2014-08-12 00:00:00 0 1
Here is my actual structure:
df <- structure(list(Date = c("2014-07-13 00:00:00", "2014-08-01 00:00:00",
"2014-08-05 00:00:00", "2014-06-28 00:00:00", "2014-05-31 00:00:00",
"2014-06-06 00:00:00", "2014-06-14 00:00:00", "2014-05-25 00:00:00",
"2014-06-24 00:00:00", "2014-06-28 00:00:00", "2014-05-30 00:00:00",
"2014-06-18 00:00:00", "2014-07-02 00:00:00", "2014-07-11 00:00:00",
"2014-05-29 00:00:00", "2014-06-19 00:00:00", "2014-07-31 00:00:00",
"2014-06-27 00:00:00", "2014-06-23 00:00:00", "2014-05-30 00:00:00",
"2014-07-13 00:00:00", "2014-08-12 00:00:00", "2014-06-13 00:00:00",
"2014-06-25 00:00:00", "2014-06-28 00:00:00", "2014-08-07 00:00:00"
), IsWin = structure(c(2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L
), .Label = c("False", "True"), class = "factor")), .Names = c("Date",
"IsWin"), row.names = 20:45, class = "data.frame")