Imputing missing values linearly in R

前端 未结 2 684
名媛妹妹
名媛妹妹 2021-01-12 18:54

I have a data frame with missing values:

X   Y   Z
54  57  57
100 58  58
NA  NA  NA
NA  NA  NA
NA  NA  NA
60  62  56
NA  NA  NA
NA  NA  NA
69  62  62
         


        
2条回答
  •  自闭症患者
    2021-01-12 19:22

    I can recommend the imputeTS package, which I am maintaining (even if it's for time series imputation)

    For this case it would work like this:

    library(imputeTS)
    df$X <- na.interpolation(df$X, option ="linear")
    df$Y <- na.interpolation(df$Y, option ="linear")
    df$Z <- na.interpolation(df$Z, option ="linear")
    

    As mentioned the package requires time series / vector input. (that's why each column has to be called seperatly)

    The package offers also a lot of other imputation functions like e.g. spline interpolation.

提交回复
热议问题