Nanair包裹没有预期的结果

问题描述 投票:0回答:1

最近,我一直在用数据集中的一些变量进行卡方检验。问题是某些变量缺少列出为-9而不是NA的值,我尝试使用一些策略来对此进行纠正:

Oak %>% replace_with_na_all(condition = ~.x == -9)

oakland_analysis_final %>%
   replace_with_na_all(condition = ~.x %in% common_na_numbers)

na_strings <-c("-9")

Oak %>%
   replace_with_na_all(condition = ~.x %in% na_strings)

用NA代替-9。使用table()命令后,我确认仍列出-9。没有明显的错误。

r missing-data chi-squared
1个回答
2
投票

怎么样?

    Oak <- data.frame(
    id = c(1,   1,  1,  1,  1,  1,  1,  1,  1,  1),
    values = c(1,   1,  -9, 2,  -9, 3,  4,  4,  -9, 5))

Oak

   id values
1   1      1
2   1      1
3   1     -9
4   1      2
5   1     -9
6   1      3
7   1      4
8   1      4
9   1     -9
10  1      5

Oak[ Oak == -9 ] <- NA

Oak

   id values
1   1      1
2   1      1
3   1     NA
4   1      2
5   1     NA
6   1      3
7   1      4
8   1      4
9   1     NA
10  1      5
© www.soinside.com 2019 - 2024. All rights reserved.