I need to insert rows in the "fev" column on days 30 and 31 that are filled with "NA" so that the data in the rows is shifted down. I tried fev$novaLin <- with(fev, as.integer(d == 30, 31 & fev == NA, NA))
, but it did not work because a column was created next to the column "fev", with indication of NAs on days 30 and 31 and without the other data. Since my dataset is very long, I need a function that automates this process.
How can I fix this?
id dia fev
1 1 0.2
2 2 0.1
3 3 0
4 4 0
5 5 0.9
6 6 0.23
7 7 0
8 8 0
9 9 0
10 10 NA
11 11 NA
12 12 NA
13 13 NA
14 14 10.2
15 15 0
16 16 0
17 17 6.7
18 18 0
19 19 0
20 20 0
21 21 0
22 22 0.3
23 23 0.7
24 24 0
25 25 0
26 26 0
27 27 0
28 28 NA
29 29 NA
30 30 5.3
31 31 0
32 1 40.5
33 2 4.8
34 3 0