0

Data test:

T   RH
1  10
2  10
3  12
4  11
5  14 

Look up Table:

T   RH   Rate
1  10     5
2  11     4
3  12     3
4  13     2
5  14     1

Output desired:

T   RH  Rate
1  10    5
2  10    NA
3  12    3
4  11    NA
5  14    1

NA because not matched with Lookup Table

What type of R-code cope with my problem? Thanks

MrFlick
  • 195,160
  • 17
  • 277
  • 295
Tugiyo
  • 31
  • 6
  • What you want is a left join. `dplyr::left_join(testdata, lookup)` or base R: `merge(testdata, loopup, all.x=TRUE)` – MrFlick Feb 17 '22 at 06:28
  • Thanks But the sequence of data and output changes, how to keep it the same? – Tugiyo Feb 17 '22 at 06:59
  • What exactly do you mean that the sequence changes? When I try with the test data the order stays the same. Is your input data.frames or data.tables? Can you not just sort to get the order you want afterward? – MrFlick Feb 17 '22 at 07:04
  • Oke Using this: dplyr::left_join(testdata, lookup) The sequence of data and ouput is the same Many thanks – Tugiyo Feb 17 '22 at 07:05
  • Oke Using this: dplyr::left_join(testdata, lookup) The sequence of data and ouput is the same Many thanks – Tugiyo Feb 17 '22 at 07:05

0 Answers0