Your function passes -9999 to each call of f and then increments it by 1. This is why it's returning -9998 each time.
You probably want to maintain the counter variable in the parent environment and update it with the <<- operator. Something like this would do the trick for your example:
f = function(x) {
if (x == "") {
counter <<- counter + 1
return(toString(counter))
} else {
return(toString(x))
}
}
counter <- -9999
sapply(c("", "", "", "", "", "1/1/1998"), f)