I need a new column of mean grouped by months and the same mean for each month repeated n number of times the month appears.
the grouped mean is calculated but they are unique values, I am unable to make it repeat for n number times side by side for months.
tn_1$GAVG = aggregate(tn_1$FATALITIES, list(tn_1$MONTH), mean)
it gives the following error
Error in `$<-.data.frame`(`*tmp*`, GAVG, value = list(Group.1 = c("01", :
replacement has 12 rows, data has 6267
the new column must display the mean for each month value.
structure(list(FATALITIES = c(1L, 2L, 5L, 5L, 3L, 3L, 3L, 4L,
8L, 1L, 7L, 4L, 3L, 4L, 12L, 4L, 1L, 2L, 3L, 1L, 0L, 0L, 4L,
1L, 0L, 5L, 0L, 12L, 3L, 2L, 4L, 5L, 1L, 22L, 0L, 1L, 2L, 4L,
7L, 3L), MONTH = c("04", "04", "04", "04", "05", "05", "05",
"05", "05", "05", "05", "05", "05", "05", "06", "06", "06", "06",
"06", "06", "06", "06", "06", "06", "06", "06", "06", "06", "06",
"06", "06", "06", "06", "06", "06", "06", "06", "06", "06", "06"
)), .Names = c("FATALITIES", "MONTH"), row.names = c(NA, 40L), class = "data.frame")