I have a dataset where I have multiple observations in a given year for a variable. I am wanting to calculate an average for each year for that variable. Here's what the data look like:
I want to get an average of each year to then plot the average of the VCF0207 variable over time.
I tried using the following code to make a temporary dataframe to get these averages for each year:
temp.df <- df %>%
group_by(VCF0004) %>%
summarize(VCF0207 = mean(VCF0207))
That didn't work. It gave me 1 variable with 1 observation. Am I missing something?
EDIT: Here is a bit more about what the data look like:
> dput(head(ts.dat,20))
structure(list(VCF0004 = structure(c(1964, 1964, 1964, 1964,
1964, 1964, 1964, 1964, 1964, 1964, 1964, 1964, 1964, 1964, 1964,
1964, 1964, 1964, 1964, 1964), label = "Year of Study", format.stata = "%9.0g"),
VCF0207 = structure(c(85, 70, 85, 85, 60, 97, 97, 50, 70,
50, 97, 97, 97, 97, 97, 97, 97, 97, 97, 85), label = "Thermometer - Whites", format.stata = "%75.0g", labels = c(`97. 97-100 Degrees` = 97,
`98. DK (exc. 1964-1968: see VCF0201 note)` = 98, `99. NA; no Post IW; form III,IV (1972); breakoff, sufficient partial (2016)` = 99
), class = c("haven_labelled", "vctrs_vctr", "double"))), row.names = c(NA,
-20L), class = c("tbl_df", "tbl", "data.frame"))