Skip to content
Prev 257352 / 398506 Next

zero fill empty cell in data.frame

you could try something along these lines:

DF <- data.frame(V1 = c(0, 0.9, " ", 0.8, 0.1, 0),
     V2 = c(0.9, " ", 0.8, 0.7, "  ", 1))

DF
sapply(DF, function (x)
     as.numeric(gsub("(^ +)|( +$)", "0", x)))


I hope it helps.

Best,
Dimitris
On 4/19/2011 11:39 AM, Simone Gabbriellini wrote: