Hi,
I'm trying to clean a dataframe that looks like this:
df <- data.frame(First = c("Mark", "John", "Anthony"),
Last = c("Joshua", "Wellberg", "Kennedy"),
Notes = c("DIS# 430477541 Plan Manager: Susan Long McArthur Community Care susan.long@mcarthur.com.au DOB: 19/04/1963 NDIS# 430477541 Start - 15/11/2018 Finish - 15/11/2019",
"Plan managed – national disability support partners – invoices@ndsp.com.au",
"Self managed
Natalia O/T
NDIS number - 431141456"),
NDIS = c(NA,NA,NA),
Col = c(NA, NA, NA))
df$Notes <- tolower(df$Notes)
I want to fill the Plan column based on the presence of certain strings in the Notes column. For example, if the Notes column contains the string "self manag", I wan to fill the Plan column with "S". I've tried the following code:
for (row in 1:df) {
if (grep("self manag", df$Notes)) {
Plan == "S"
}
}
When I try this, I get an error saying:
Error in 1:df : NA/NaN argument
In addition: Warning message:
In 1:df : numerical expression has 5 elements: only the first used
What am I doing wrong here?
Thank you kindly for your help.