I have 2 data frames with 85 different IDs, and 40 different groups, so I'd like to use a loop as it is too much data to go through by hand.
Here's what I need to do:
I want to merge the two data frames by ID for each group, make a new column that multiplies Data X Area, then extract separate csvs by each group. Each ID in each group has a different area, but number of IDs is the same per group.
Here's the dummy data:
Group <- c(100,100,100,103,103,103,110,110,110)
ID <- c(1,2,3,1,2,3,1,2,3)
Area <- c(23,4,3,23,0,.5,7,2,33)
x <- data.frame(Group, ID, Area)
ID <- c(1,2,3)
Data <- c(.002,.4,1)
y <- data.frame(ID, Data)
Desired Output (different csv for each group):
Group ID Area Data A.D
100 1 23 .002 .046
100 2 4 .4 1.6
100 3 3 1 3