1

I want to do a simple linear interpolation for NA values of each row of a big matrix (52017455 x 150), generally I can do this by using the na.approx function in zoo package with apply function, however, this is too slow, I wonder whether there is a Rcpp or data.table function or packge to do this? Generally, my data is spatial-temporal grid of remotesensing, I have tried to using approxNA function in raster package, but it is not fast enough.

x=rnorm(120)
x[c(3,8,16,22)]=NA
data=data.frame(t(x))
data=data[rep(1,52017455),]
result=apply(data,1,zoo::na.approx)
earclimate
  • 375
  • 1
  • 14
  • 1
    For this, I'd recommend rolling your own Rcpp implementation. Where performance is critical and the problem is simple (but narrow) It's unlikely that there's an off-the-shelf implementation that will be able to outperform it. – Hugh Feb 01 '20 at 03:47
  • It would probably enhance your question if you could add the actual size of your dataset. Your example is good, but runs in the blink of an eye -- an appropriate solution might incur a lot of overhead. – Hugh Feb 01 '20 at 03:50
  • https://stackoverflow.com/questions/30717150/apply-function-by-row-in-data-table-using-columns-as-arguments https://stackoverflow.com/questions/48879643/rowwise-matrix-multiplication-in-r https://stackoverflow.com/questions/54080116/iterate-over-vectors-from-an-imported-dataframe-row-wise https://stackoverflow.com/questions/47737230/method-to-operate-on-each-row-of-data-table-without-using-apply-function – IRTFM Feb 01 '20 at 05:22
  • @Hugh Thanks for your suggestion. The actual size of my dataset is about 52017455 x 150. – earclimate Feb 01 '20 at 05:42

0 Answers0