在列中删除NA值为NA的行
我在R中有一个dataset.csv。我想从等级列中删除所有的NA值。在列中删除NA值为NA的行
列是这样
Rank State NA District of Columbiaâ€
1 Connecticut
2 New Jersey
3 Massachusetts
4 Maryland
5 New Hampshire
6 Virginia
7 New York
8 North Dakota
9 Alaska
10 Minnesota
11 Colorado
12 Washington
13 Rhode Island
14 Delaware
15 California
16 Illinois
17 Hawaii
18 Wyoming
19 Pennsylvania
20 Vermont
NA United States
21 Iowa
这个CSV的数据框被称为RacePerState
我已经试过
subset(RacePerState, State!="United States" && State!="District of Columbiaâ€" && !="Puerto Ricoâ€") RacePerState <- RacePerState[!(RacePerState$Rank=="NA"),]
但代码当我写数据帧到CSV的数据仍然存在。
任何帮助?
回答:
RacePerState <- subset(RacePerState, !is.na(Rank))
或
RacePerState <- RacePerState[!is.na(RacePerState$Rank), ]
或
RacePerState <- RacePerState[complete.cases(RacePerState), ]
或
require(dplyr); require(magrittr);
RacePerState %>% na.omit();
以上是 在列中删除NA值为NA的行 的全部内容, 来源链接: utcz.com/qa/263807.html