I was trying to gsub some dirty data like these "cds 9"; "cTT-9";"lee" in the data frame by building a function; and then lapply it to the dataframe
I have tested for several input like "cds 9"; "cTT-9";"lee" and they all gave me the expected results as "CDS9";"CTT9";"LEE"
`data_clean <- function(arg) {
outcome<-arg
output1<-gsub(pattern=" ",replacement="",arg)
if (output1!=arg){outcome<-output1}
output2<-gsub(pattern="-",replacement="",arg)
if (output2!=arg){outcome<-output2}
toupper(outcome)
}
df<-lapply(df, data_clean)`
However,when i lapply the function to my data frame, it printed out this:
"Error in if (output1 != arg) { : argument is of length zero"
P.S. the data frame looks like this: enter image description here