I have two data frames df1 and df2:
group=c("Group 1", "Group 2", "Group3","Group 1", "Group 2", "Group3") year=c("2000","2000","2000", "2015", "2015", "2015") items=c("12", "10", "15", "5", "10", "7") df1=data.frame(group, year, items) year=c("2000", "2015") items=c("37", "22") df2=data.frame(year,items)
df1 contains the number of elements per year and is divided by a group, and df2 contains the total number of elements per year
I am trying to create a for loop that will calculate the proportion of elements for each type of group. I am trying to do something like:
df1$Prop=""
where the loop should get the proportion for each element type (by getting the value from df1 and dividing by the total value in df2) and list it in a new column, but this code does not work.
source share