过滤而不删除NA

时间:2016-12-27 14:06:15

标签: r dplyr

我有一个带有代理的data.frame,用于将来的日期2099-01-01,以及缺少的数据。我试图过滤掉未来的日期,而不是删除NA。我试过了

inactive1 <- filter(`Latest Active Date` < "2099-01-01")` 

但这也删除了NA,

也是如此
inactive1 <- filter(`Latest Active Date` != "2099-01-01")

有什么建议吗?

test3 <- structure(list(`EI Program Type` = c("EI - Infant/Toddler", "EI - Infant/Toddler","EI - Infant/Toddler", "EI - Infant/Toddler", "EI - Infant/Toddler","EI - Infant/Toddler", "EI - Infant/Toddler", "EI - Infant/Toddler","EI - Infant/Toddler", "EI - Infant/Toddler"), `MCI ID` = c("770328087","570325112", "990627838", "070302077", "710347653", "250277177","470381260", "600330482", "270264208", "391186487"), `Record Status` = c("Inactive","Inactive", "Inactive", "Inactive", "Inactive", "Inactive", "Inactive","Inactive", "Inactive", "Inactive"), `Detail/ Reason` = c("Part B eligibility not determined (<33 months)","Successful completion of plan (IFSP/IEP)", "Successful completion of plan (IFSP/IEP)","Eligible for IDEA Part B (<33 months)", "PELICAN EI Data Correction","Not eligible for Part B - referrals (<33 months)", "Parent declined EI services","Eligible for IDEA Part B (<33 months)", "Eligible for IDEA Part B (<33 months)","Attempts to contact unsuccessful"), `Effective Begin Date` = structure(c(16049,16021, 15561, 16173, 17106, 15666, 16217, 16749, 15968, 16560), class = "Date"), `Effective End Date` = structure(c(47117,16146, 47117, 47117, 47117, 47117, 47117, 16772, 47117, 16700), class = "Date"), `Case Closure Date` = structure(c(16039,15991, 15546, 16166, 17062, 15589, 16210, 16738, 15909, 16553), class = "Date"), `Latest Active End Date` = structure(c(15882,16177, 15341, 16084, 16602, 15537, NA, 16784, 15744, 17030), class = "Date")), .Names = c("EI Program Type","MCI ID", "Record Status", "Detail/ Reason", "Effective Begin Date","Effective End Date", "Case Closure Date", "Latest Active End Date"), row.names = c(360065L, 493021L, 118486L, 448679L, 673846L,206565L, 914550L, 756388L, 297259L, 853157L), class = "data.frame")  

1 个答案:

答案 0 :(得分:-1)

根据您的问题建议使用filter中的dplyr

library(dplyr)
filter(test1, `Latest Active End Date` < "2099-01-01" | is.na(`Latest Active End Date`))