0

I have a dataset.csv in R. I want to remove all NA values from the Rank columns.

The column is like this

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

The dataframe of this CSV is called RacePerState

The code I have tried

subset(RacePerState, State!="United States" && State!="District of Columbiaâ€" && !="Puerto Ricoâ€")

RacePerState <- RacePerState[!(RacePerState$Rank=="NA"),]

But when i write the dataframe to a csv the data is still there.

Any help?

Konrad Rudolph
  • 482,603
  • 120
  • 884
  • 1,141

1 Answers1

2
RacePerState <- subset(RacePerState, !is.na(Rank))

or

RacePerState <- RacePerState[!is.na(RacePerState$Rank), ]

or

RacePerState <- RacePerState[complete.cases(RacePerState), ]

or

require(dplyr);
require(magrittr);
RacePerState %>% na.omit();
Maurits Evers
  • 42,255
  • 4
  • 27
  • 51