0

I have a data frame in which I want to apply rollapply function. I can have up to 5% of NAs within a column.

I would like to omit the NA but it seems to me there is no na.omit. Alternatively I would be happy to fill the missing value with last known value in the column.

I don't see how to do that with ??rollapply

Would anyone have an idea? Many thanks,

Vincent

Edit: The function I am working on is:

function(TableVolume,n){
TableM = TableVolume
for (i in 2:ncol(TableVolume)){TableM[,i]=rollapply(TableVolume[,i],n,FUN=mean,partial=TRUE}
TableM=TableM[n:nrow(TableVolume),]
return(TableM)
}
VincentH
  • 1,009
  • 4
  • 13
  • 24
  • 1
    Include it in the function you are applying with roll apply: `rollapply(...,function(x) na.omit(x)`. PS: A reproducible example would be good: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Etienne Low-Décarie Jul 04 '12 at 12:38
  • There is also an `na.locf` function that would fill with the last known value. – IRTFM Jul 04 '12 at 12:39

0 Answers0