I am looking to make this table below. I have the first 2 columns of data for 2 years and wanting to calculate the daily mean price and apply it to all relevant days.
Publish_Date | Product_Price | Daily_Mean |
---|---|---|
2019-07-01-- | 146---------- | 142------- |
2019-07-01-- | 144---------- | 142------- |
2019-07-01-- | 136---------- | 142------- |
2019-07-02-- | 120---------- | 123------- |
2019-07-02-- | 126---------- | 123------- |
2019-07-02-- | 123---------- | 123------- |
2019-07-03-- | 112---------- | 112------- |
I have tried the following:
TGPDailyMean = aggregate(Product_Price ~ Publish_Date, TGP, mean)
but it only gives one value per day, shortening the amount of rows by a factor of 3 or so. I need the amount of rows to be the same so I can take the difference between another dataframe and Daily_Mean.
I have also tried:
TGP$DailyMean = lapply(TGP$Product_Price, mean)
but this only replicates the values in Product_Price and does not find the mean per day.