I have a similar, but not quite the same question to R apply function with multiple parameters
I have a dataset with two variables RSHIFTSTART and RSHIFTEND (amongst other variables). These variables contain times eg. 23:30:00 or 00:00:00. I'd like to replace RSHIFTSTART and RSHIFTEND with NA wherever BOTH variables are zero ie. '00:00:00'.
I've written a function which I think may do the job:
# Change '00:00:00' to NA where both variables are '00:00:00'
zeroTime=function(x,y) {
if (x=='00:00:00' & y=='00:00:00') {
replace(x,x=='00:00:00',NA)
replace(y,x=='00:00:00',NA)
}
}
My question is how to apply this function to update the dataset's variable ie. supplying two arguments to it. I tried:
sapply(rosterSample$RSHIFTSTART,rosterSample$RSHIFTEND,zeroTime)
but this syntax is incorrect. Perhaps I'll be restricted to changing just one variable per call ie. RSHIFTSTART or RSHIFTEND, that's OK.
Any ideas? Thanks Pete