I have a below data frame for which I must search the string values and return the other columns It should return values depending on the input I give
Ex :
Enter the number you want to search
Input 1 = 14
Inout 2 = 16
Combining above two, I have 14,16
as a string, then it should return me the below
rhs name
15 salt
Below is the Dataframe where we can search our inputs(it should search only on lhs )
DF:
lhs rhs name
32,39,6 65 jackfruit
39,6,65 32 coffee
14,16,26 15 salts
16,20,4 26 marshmallows
16,26,33 4 veggies
53 31 candy
This search should accept for any number of strings and should be able to search.
For suppose, my input is 14,16,26
it should return the value
rhs name
15 salt
Also, if its only 16, then it should return
Rhs name
15 salts
26 marshmallows
4 veggies.
I have tried using the below code but it just uses the order for example:
CODE:
df[grep('16,20', df$lhs),]
output :
rhs name
26 marshmallows
But if change my search like below,
CODE:
df[grep('16,4', df$lhs),] (#leaving the number 20 )
the above one gives me an error.
Expected output :
rhs name
26 marshmallows