I have the following data set:
hs desc
1 34 a
2 53 b
3 64 c
4 54 d
5 34 <NA>
6 34 <NA>
7 53 <NA>
8 53 b
9 53 b
10 53 <NA>
首先,在一个理想的世界里,每小时休息都具有一定价值,因此, des应该具有另一个价值。 例如,每看34小时,就请看“a” des。 但是,正如你从我的数据集中可以看到的那样,我国有许多国民。 我需要用相应的价值观填写这些单元。
It may appear simple from the start. I could use ifelse
or case_when
. But that s not enough, because my real database has A LOT of different hs codes
我需要这样做:
- It should see the filled cells and understand that everytime a hs has a certain value, desc should have a corresponding value
- But the code should do this based on the already filled values. I m not telling my code explicitly that if hs=34, then desc=a. He knows it by itself after scanning my dataset
- Once the code itself knows what desc should be based on hs, then it should fill all NAs apropriately
例如:
- The code scans my dataset and sees, in any already filled row, that if hs=34, then desc=a.
- After that, the code should put desc=a everytime he sees hs=34
我知道这令人困惑,但我希望有人理解我。