I have the two data frames -
- Dataframe 1:
df1 <- read.table(text = "
Numbers
40500
4400025
14515
51432", header = TRUE)
- Dataframe 2:
df2 <- read.table(text = "
ColumnA ColumnB ReturnC ReturnD
32000 41400 rose apple
51400 57389 orchid orange
12523 16357 jasmine grapes
10528 11034 lily melon ", header = TRUE)
This is what I want -- Check if each value from Numbers
in dataframe 1 is between ColumnA
and ColumnB
of dataframe 2. If it is, I want the corresponding ReturnC
and ReturnD
from dataframe 2 in the output.
If it is not, I want NA
.
E.g. 51432
is in between column A and column B. Orchid and orange are the corresponding values in dataframe 2 for that intersection. This is how the final dataset will look like:
Final:
Numbers Output1 Output2
40500 rose apple
4400025 NA NA
14515 jasmine grapes
51432 orchid orange
How should I do this in R
? -- Thank you for your help!