I am having difficulty dealing with this step of data management in R while trying to aggregate data at the monthly level.
I have two examples, one essentially represents where I am stuck at now in my process of cleaning and aggregating, and the second represents what I would like it to look like.
What it looks like now:
month <- c("January", "January", "February", "March", "April", "April",
"May", "June", "July")
year <- c(2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014)
count1 <- c(3, 0, 1, 2, 0, 8, 1, 1, 1)
count2 <- c(0, 2, 1, 4, 6, 0, 1, 1, 1)
count3 <- c(1, 1, 1, 1, 1, 1, 0, 0, 1)
df <- data.frame(month, year, count1, count2, count3)
What I would like it to look like:
month2 <- c("January", "February", "March", "April", "May", "June", "July")
year2 <- c(2014, 2014, 2014, 2014, 2014, 2014, 2014)
count1a <- c(3, 1, 2, 8, 1, 1, 1)
count2a <- c(2, 1, 4, 6, 1, 1, 1)
count3a <- c(1, 1, 1, 1, 0, 0, 1)
df2 <- data.frame(month2, year2, count1a, count2a, count3a)
As you will notice, I am having some months counted twice and their observations are not on the same row as the other observations that I am using for the same month.