1
dfmiss=data.frame(x=c(1,4,6,NA,7,NA,9,10,4,3),
       y=c(10,12,NA,NA,14,18,20,15,12,17),
       z=c(225,198,520,147,NA,130,NA,200,NA,99),
       v=c(44,51,74,89,45,55,25,36,75,25))

我使用mi包估算了这个不完整的数据,如下所示:

istall.package("mi")
library(mi)
    mdf <- missing_data.frame(dfmiss) # change dataframe to missing_data.frame
    imp=mi(mdf)
     complete(imp,1)
               x         y         z  v missing_x missing_y missing_z
    1   1.000000 10.000000 225.00000 44     FALSE     FALSE     FALSE
    2   4.000000 12.000000 198.00000 51     FALSE     FALSE     FALSE
    3   6.000000 -2.631072 520.00000 74     FALSE      TRUE     FALSE
    4   9.189989 14.760334 147.00000 89      TRUE      TRUE     FALSE
    5   7.000000 14.000000 188.37644 45     FALSE     FALSE      TRUE
    6  11.127962 18.000000 130.00000 55      TRUE     FALSE     FALSE
    7   9.000000 20.000000  92.30703 25     FALSE     FALSE      TRUE
    8  10.000000 15.000000 200.00000 36     FALSE     FALSE     FALSE
    9   4.000000 12.000000 184.29575 75     FALSE     FALSE      TRUE
    10  3.000000 17.000000  99.00000 25     FALSE     FALSE     FALSE

complete()命令返回了完整的数据集,但我想返回这个完整的数据集,但不包含(TRUE / FALSE 列)[missing_x,missing_y,missing_z]。

4

1 回答 1

1

您可以删除多余的列:

> out <- complete(imp,1)
> out[, !grepl("missing_", names(out))]
            x        y         z  v
1   1.0000000 10.00000 225.00000 44
2   4.0000000 12.00000 198.00000 51
3   6.0000000 -1.34534 520.00000 74
4  -0.7613754 10.65513 147.00000 89
5   7.0000000 14.00000 183.87114 45
6  10.9100600 18.00000 130.00000 55
7   9.0000000 20.00000  83.41713 25
8  10.0000000 15.00000 200.00000 36
9   4.0000000 12.00000 152.67158 75
10  3.0000000 17.00000  99.00000 25
于 2016-01-24T00:04:17.497 回答