DmitryKras
DmitryKras

Reputation: 19

Why I get totally empty dataframe when trying to eliminate rows with NA?

Having dataframe df, I am trying to remove rows with the specific value in the column Status.

That's what I do: df<-df[!df$Status=="ВАКАНСИЯ",]. As a result I receive dataframe with only NA values.

Interestingly enough, even if I do df<-df[df$Status=="ВАКАНСИЯ",] (witthoout negation !) I still receive NA dataframe.

What do I do wrong?

Upvotes: 1

Views: 73

Answers (1)

JBGruber
JBGruber

Reputation: 12410

This question can't really be answered (as you don't show your data) but I take a wild guess and say you misspelled your column name. In that case the condition is neither TRUE nor FALSE for any row but logical(0) instead, which means all rows are removed:

df <- data.frame(id = 1:2,
                 Statuss = c("ВАКАНСИЯ", "Good"), stringsAsFactors = FALSE)

df[!df$Statuss == "ВАКАНСИЯ",] #spelled correctly
#>   id Statuss
#> 2  2    Good

df[!df$Stats == "ВАКАНСИЯ",] #misspelled column name
#> [1] id      Statuss
#> <0 rows> (or 0-length row.names)

Created on 2019-10-31 by the reprex package (v0.3.0)

There is no error or warning displayed in this case.

Upvotes: 1

Related Questions