I would like to plot some data in set with the frequency of x over time y which is in years. I've been able to manipulate the data into a data frame where I have the frequency of certain binary string data. As it currently is have I have the frequency by year with two lines per year in order to plot the frequency of the different binary outcomes. However, I would like to plot the percentage of the total of these observations by year.
df <- data.frame( x = c("1980", "1980", "1981", "1981", "1982", "1982" ),
y = c("yes", "no", "yes", "no", "yes", "no"),
z = c("26", "18", "32", "12", "18", "16"))
Initially I tried this code by aggregating the observations by year but it only has 32 rows of data when I need to have 64.
df1$Sum <- aggregate(df1$z, by=list(df1$x), FUN=sum)
Is there someway I can duplicate the observations by year so that in a new column is contains the sums of both "yes" and "no" in 1980 for both rows 1 and 2?