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
7 Chiquita mazamorra Buro 123
6 Chiquita AM 2F 210
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
This is the final desired output
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
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.
Aucun commentaire:
Enregistrer un commentaire