Reproduceable dataset
data1 <- data.frame(ID = c(1,2), Description = c("Chiquita","Chiquita mazamorra"), Max = c(200,125))
data2 <- data.frame(ID = c(1,2,3,4,5,6,7), Description = c("Chiquita mini", "Chiquita Oriville","Chiquita 24h","Manzano Chiquita 5j...","Chiquita mazamorra 1,2h..","Chiquita mazamorra Buro","Chiquita AM 2F"), Max = c(24,110,80,90,134,123,210))
I have a dataset , data1, as shown below
Id Description Max
1 Chiquita 200
2 Chiquita mazamorra 125
I have another dataset, data2, as shown below
Id Description Actual
1 Chiquita mini 24
2 Chiquita Oriville 110
3 Chiquita 24h 80
4 Manzano Chiquita 5j... 90
5 Chiquita mazamorra 1,2h... 134
6 Chiquita mazamorra Buro 123
7 Chiquita AM 2F 210
8 Chiquita..... 124
9 Chiquita(P) 213
10 Chiquita, mazamorra, S 188
If statement should check if the Data2 Description contains this character in data2$Description Chiquita mazamorra, if yes then check if Data2$Actual > Data1$Max. If Yes then Results == Good, else Small. Note there can be other characters after Chiquita mazamorra like for example Chiquita mazamorra 1,2h.. this is okay, but not Chiquita mazamorra Buro
Similarly another ifelse should check if the Data2 Description contains Chiquita if yes then check if Data2$Actual > Data1$Max. If Yes then Results == Good, else Small. There can be other characters after Chiquita like for example Chiquita 24h or Chiquita AM 2F these are okay but not Chiquita mini or Chiquita Oriville
This is the final desired output (data2)
Id Description Actual Result
1 Chiquita mini 24 NA
2 Chiquita Oriville 110 NA
3 Chiquita 24h 80 Small
4 Manzano Chiquita 5j... 90 NA
5 Chiquita mazamorra 1,2h... 134 Good
7 Chiquita mazamorra Buro 123 NA
6 Chiquita AM 2F 210 Good
8 Chiquita..... 124 Small
9 Chiquita(P) 213 NA
10 Chiquita, mazamorra, S 188 Good
I have know this can be done using a combination of grepl and ifelse statements I am not very confident ? Maybe there is a better way of doing this, I dont know, I am getting very confused. Need help.