replacing NA with monthly mean value by condition

Dear All:

I have a daily price series. but some values in the price is NA and i want to replace it with that month's mean price value. I tried to run a for and if loop, but fail to deal with this.
Any help will be greatly appreciated.

date Price
2020-01-01 10
2020-01-02 23
2020-01-03 NA
2020-01-04 50
.
.
.
2020-01-31 67
2020-02-01 80
.
.
.
2020-11-10 100

Please note that not every month has NA values.

its not clear what representation of time series you are using. and particular package/class involved?
Could you share representative data here ? perhaps use dput(yourobjectname) so you can copy and paste it as runnable code.

Hi, thanks so much.
I solved it by using na.aggregate.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.