我在R中有一个dataset.csv。我想从Rank列中删除所有NA值。
列就像这样
name
此CSV的数据框称为RacePerState
我试过的代码
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时,数据仍然存在。
任何帮助?
答案 0 :(得分:2)
RacePerState <- subset(RacePerState, !is.na(Rank))
或
RacePerState <- RacePerState[!is.na(RacePerState$Rank), ]
或
RacePerState <- RacePerState[complete.cases(RacePerState), ]
或
require(dplyr);
require(magrittr);
RacePerState %>% na.omit();