I am trying to update a custom function below, to avoid outputting blank/Null values in the solution.
checkDifference = function(A,B) {
Av=strsplit(A,', ')[[1]]
Bv=strsplit(B,', ')[[1]]
Cv=setdiff(Bv,Av)
C=paste(Cv,collapse=', ')
return (C)
}
output=mapply(FUN=checkDifference,input1,input2)
I have tried adding an If statement below and it returns all blank rows of data.
output=if mapply(FUN=checkDifference,input1,input2) isNull then "NoMissingTimeSheets"
The simplest way to do this would be to modify checkDifference:
checkDifference = function(A,B) {
Av=strsplit(A,',')[[1]]
Bv=strsplit(B,',')[[1]]
Cv=setdiff(Bv,Av)
C=paste(Cv,collapse=',')
C=ifelse(C=='','NoMissingTimeSheets',C)
return (C)
}
output=mapply(FUN=checkDifference,input1,input2)
That is adding this line within the function:
C=ifelse(C=='','NoMissingTimeSheets',C)
because the function is applied to the two inputs (input1 and input2) as vectors, element by element, using mapply. Also, the original result C is never null but can be an empty string, so it is compared to ''.