I have a data set which has gaps in one of the columns (temp). I am trying to fill the gaps using the "temp" data from a "sensor" or mean of "sensors" within the same "treatment", and of course same date stamp. I am trying to do this using tidyverse/lubridate.
date treatment sensor temp
1/01/2019 1 A 30
2/01/2019 1 A 29.1
3/01/2019 1 A 21.2
4/01/2019 1 A NA
1/01/2019 1 B 20.5
2/01/2019 1 B 19.8
3/01/2019 1 B 35.1
4/01/2019 1 B 23.5
1/01/2019 2 C 31.2
2/01/2019 2 C 32.1
3/01/2019 2 C 28.1
4/01/2019 2 C 31.2
1/01/2019 2 D NA
2/01/2019 2 D 26.5
3/01/2019 2 D 27.9
4/01/2019 2 D 28
This is what I am expecting:
date treatment sensor temp
1/01/2019 1 A 30
2/01/2019 1 A 29.1
3/01/2019 1 A 21.2
4/01/2019 1 A 23.5
1/01/2019 1 B 20.5
2/01/2019 1 B 19.8
3/01/2019 1 B 35.1
4/01/2019 1 B 23.5
1/01/2019 2 C 31.2
2/01/2019 2 C 32.1
3/01/2019 2 C 28.1
4/01/2019 2 C 31.2
1/01/2019 2 D 31.2
2/01/2019 2 D 26.5
3/01/2019 2 D 27.9
4/01/2019 2 D 28
Many thanks for your help.