I am working with two different data sets, and I'd like to move data from one to the other. I'm thinking of it this way: One contains the results, paired with the correct factor (HTm), and I want to spread those out over another frame. Here is the first frame:
head(five)
Week Game.ID VTm VPts HTm HPts HDifferential VDifferential
1 1 NFL_20050908_OAK@NE OAK 20 NE 30 10 -10
2 1 NFL_20050911_ARI@NYG ARI 19 NYG 42 23 -23
3 1 NFL_20050911_CHI@WAS CHI 7 WAS 9 2 -2
4 1 NFL_20050911_CIN@CLE CIN 27 CLE 13 -14 14
5 1 NFL_20050911_DAL@SD DAL 28 SD 24 -4 4
6 1 NFL_20050911_DEN@MIA DEN 10 MIA 34 24 -24
VTm.f HTm.f average
1 OAK NE 19.4375
2 ARI NYG 19.4375
3 CHI WAS 19.4375
4 CIN CLE 19.4375
5 DAL SD 19.4375
6 DEN MIA 19.4375
> tail(five)
Week Game.ID VTm VPts HTm HPts HDifferential VDiff
262 19 NFL_20060114_WAS@SEA WAS 10 SEA 20 10 -10
263 19 NFL_20060115_CAR@CHI CAR 29 CHI 21 -8 8
264 19 NFL_20060115_PIT@IND PIT 21 IND 18 -3 3
265 20 NFL_20060122_CAR@SEA CAR 14 SEA 34 20 -20
266 20 NFL_20060122_PIT@DEN PIT 34 DEN 17 -17 17
267 21 NFL_20060205_SEA@PIT SEA 10 PIT 21 11 -11
VTm.f HTm.f average
262 WAS SEA 0
263 CAR CHI 0
264 PIT IND 0
265 CAR SEA 0
266 PIT DEN 0
267 SEA PIT 0
and here is the other (aggregated means from the first frame).
head(fiveINFO)
HTm HPts VPts average
1 ARI 19.87500 19.00000 19.43750
2 ATL 24.75000 19.12500 21.93750
3 BAL 19.37500 13.75000 16.56250
4 BUF 16.50000 17.37500 16.93750
5 CAR 25.12500 23.27273 24.19886
6 CHI 18.77778 14.00000 16.38889
tail(fiveINFO)
VTm HPts VPts average
27 SEA 21.00 25.000 23.0000
28 SF 30.75 12.625 21.6875
29 STL 28.00 22.000 25.0000
30 TB 15.75 15.375 15.5625
31 TEN 28.00 14.750 21.3750
32 WAS 20.60 18.800 19.7000
For reference, this data is looking at NFL scores. I want to take the averages in fiveINFO, frame two, and move them to the corresponding team in the first frame. five is 266 rows long, while fiveINFO is 32 rows — fiveINFO contains each HTm only once, while five contains each one 8-10 times, depending on the number of home games each team plays. I found several answers that seemed similar, but with much smaller data sets. I don't want to merge the two; I want the averages data from the second frame to be spread across the appropriate HTm values in the first frame.
I'm imagining I'll need to use some kind of for loop for this, but everything I'm doing is striking out. Help?