Questions tagged [na.approx]

11 questions
3
votes
2 answers

Reverse/backward na.approx

I have a date vector with leading NAs and I'd like to generate an approximate sequence for these NAs using na.approx from package zoo. na.approx does not work for leading NAs: x <-…
Pierre Lapointe
  • 16,017
  • 2
  • 43
  • 56
2
votes
1 answer

Substitute Average of Previous and Next Available Values of Field for NA Values in Dataframe

The sample data set of available much bigger data set is in following format: Station <-c("A","A","A","A","A","A","A","A","A","A","A","A","A","A","A") Parameter <-c(2,3,NA,4,4,9,NA,NA,10,15,NA,NA,NA,18,20) Par_Count…
Ajay
  • 320
  • 2
  • 11
1
vote
1 answer

na.approx with multiple specific columns

I have a dataframe (DF) with many columns (colA, colB, colC, colD, . . . . ). I would like to apply the na.approx function, with group_by, to several, but not all, columns in the dataframe. I succeeded in applying the na.approx and group_by…
Stephen
  • 473
  • 4
  • 11
1
vote
0 answers

R: speed up na.approx for large matrix by row

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…
earclimate
  • 375
  • 1
  • 14
1
vote
1 answer

Error: replacement has 1810947 rows and data has 1810956 (same each time) for pupil data

I have a large dataframe in R (data) made up of 23 .gazedata files (one for each subject): filenames <- list.files("~/Desktop/DUT Analyses 2019", pattern = "*.gazedata", full.names = TRUE) ldf <- lapply(filenames, read_tsv) data <- do.call("rbind",…
0
votes
1 answer

na.approx and na.locf not behaving properly

I'm trying to calculate imputated values for a time series for different countries. This piece of code worked fine before, but now the impuated values are all wrong ... I can't figure out the problem, I've tried everything I could think of. Our…
0
votes
1 answer

Apply na.approx on row and output dataframe in R

Given the following dataframe: df1 <- data.frame(Company = c('A','B','C','D','E'), `X1980` = c(NA, 5, 3, 8, 13), `X1981` = c(20, NA, 23, 11, 29), `X1982` = c(NA, 32, NA, 41, 42), …
Connor Uhl
  • 75
  • 1
  • 9
0
votes
2 answers

na.approx function does not produce correct timestamps

I have a large dataset of electric load data with a missing timestamp for the last Sunday of March of each year due to daylight saving time. I have copied below a few rows containing a missing timestamp. structure(list(Date_Time =…
Iro
  • 37
  • 5
0
votes
1 answer

How to apply na.approx to a row in a matrix?

I am trying to make an interpolation for all the rows in a dataframe. I am using apply(data_final,2,na.approx). This make the interpolation for the values but some are out of range. If I use na.approx(data_final[8,]) instead, I get a different value…
0
votes
1 answer

Correct use of na.approx in data.table and pipe

I am very new to data.table and would like to try it out to see if it makes my analysis faster. I mainly use knitr to compile .rnw files (which I tend to compile many times per hour so I want it to be as fast as possible). I have posted a sample…
Prevost
  • 677
  • 5
  • 20
0
votes
0 answers

How to interpolate using na.approx when boundary value is an NA

I want to adjust the end values of interpolation for missing values in such a way that the difference between the next set of non-NA values are applied to determine the first one. for example, this is the code library(zoo) >…
ashleych
  • 1,042
  • 8
  • 25