I have large number of columns in my dataframe over 4000. One column is of Date and rest are Companies (Column Names). I have daily obervations for 14 years (as rows) making it be 164 months .I want to calculate mothly averages based on the Date column and most important of all the average should only be calculated when there are atleast 15 observations for each column(company) otherwise should return NA.
df<- Spread
Date A B C
2000-01-04 0.062893082 0.030769231 NA
2000-01-05 0.062893082 0.015503876 NA
2000-01-06 0.062893082 NA NA
2000-01-07 0.062893082 NA NA
2000-01-10 0.062893082 NA NA
2000-01-11 0.062893082 NA NA
2000-01-12 0.062893082 NA NA
2000-01-13 0.062893082 NA NA
2000-01-14 0.062893082 NA NA
2000-01-17 0.052910053 NA NA
2000-01-18 0.031413613 NA NA
2000-01-19 0.052910053 NA NA
2000-01-20 0.051282051 NA NA
2000-01-21 0.051282051 0.014184397 NA
2000-01-24 0.051282051 0.014184397 NA
2000-01-25 0.051282051 0.014184397 NA
2000-01-26 0.051282051 0.014184397 NA
2000-01-27 0.051282051 0.019914651 NA
2000-01-28 0.031088083 0.028571429 NA
2000-01-31 0.031088083 0.028571429 NA
The output I want
Monthly<- df
Month A B C
Jan-2000 0.053656996 NA NA
I would really apprecaite your help. And any ideas I want round off these values to 4 decimal places for instance 0.062893082 to 0.0628.
Aucun commentaire:
Enregistrer un commentaire