I'm struggling with what seems like it should be a simple extension of a previous question I'd asked here.
I'm trying to aggregate over (a) a range of dates and (b) a factor variable. Sample data might be:
Brand Day Rev RVP
A 1 2535.00 195.00
B 1 1785.45 43.55
C 1 1730.87 32.66
A 2 920.00 230.00
B 2 248.22 48.99
C 3 16466.00 189.00
A 1 2535.00 195.00
B 3 1785.45 43.55
C 3 1730.87 32.66
A 4 920.00 230.00
B 5 248.22 48.99
C 4 16466.00 189.00
Thanks to helpful advice, I've figured out how to find the mean revenue for brands over a period of days using data.table:
new_df<-df[,(mean(Rev)), by=list(Brand,Day)]
Now, I'd like to create a new table where there is a column listing the coefficient estimate from an OLS regression of Rev by Day for each brand. I tried to do this as follows:
new_df2<-df[,(lm(Rev~Day)), by=list(Brand)]
That doesn't seem quite right. Thoughts? I'm sure it's something obvious I've missed.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…