2
I have a dataframe with two columns, being them GL GLDESC and wanted to add a third column called KIND based on column data GLDESC.
Dataframe:
GL GLDESC
1 515100 Payroll-ISL
2 515900 Payroll-ICA
3 532300 Bulk Gas
4 551000 Supply AB
5 551000 Supply XPTO
6 551100 Supply AB
7 551300 Material Interno
Whereas:
If the
GLDESCcontain the wordPayrollanywhere string,KINDget back to mePayrollIf the
GLDESCcontain the wordSupplyanywhere string,KINDget back to meSupplyIn all other cases,
KINDisOther.
What is solved without problems with:
DF$KIND <- ifelse(grepl("supply", DF$GLDESC, ignore.case = T), "Supply",
ifelse(grepl("payroll", DF$GLDESC, ignore.case = T), "Payroll", "Other"))
But with that, I have everything you quote Supply, for example, classified. However, as in lines 4 and 5 of the DF, the same GL has two Supply, which for me is unnecessary. Actually, I need just one kind of GLDESC be classified case for the same GL the string repeats itself.
How to?
Edited: Deleting duplicates is not an output I can take. I need to keep everything where it is, just sort the first and skip the second.