NA values are not recognized properly using dplyr

C. Sebastian

I have a dataset with two columns, in one of them are missing values. I load it using

data <- read_excel("file.xlsx") %>%
  select("ID", "Value")

The tibble looks like that

ID Value
1 2
NA 4
32 1

The NAs are recognized as such. However, I use

data["ID"=="NA"] <- NA

to ensure that this is not the problem (R: is.na() does not pick up NA value).

When I try to filter:

data %>%
filter(!is.na(ID))

the whole tibble stays the same, and no row is deleted. So I try

data %>%
mutate(
isna <- is.na(ID)
)

and all isna are FALSE.

Why doesn't recognize dplyr the NAs?

I am grateful for every help!

MonJeanJean

Welcome to SO! Use this to get NAs mutated and then delete the NAs:

data <- data %>% 
  mutate(ID = ifelse(ID == "NA",NA,ID)) %>%
  filter(!is.na(ID))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to count total non-na values using dplyr?

replace duplicate values with NA in time series data using dplyr

Concatenate string field using dplyr when some values are NA

Sum() in dplyr and aggregate: NA values

dplyr summary of values returns NA

Ignore NA values in filtering with dplyr

Set certain values to NA with dplyr

dplyr join define NA values

Setting multiple values to NA with dplyr

remove NA using dplyr package & counting non-zero values in R

Calculate the rowwise mean when a maximum number of NA values is given for a set of columns using dplyr

How to recode only some values in R to NA using dplyr::if_else?

Replace NA's in set of columns by values from another set of columns using dplyr

using R dplyr replace NA with group mean but omitting some values from group before mean calculation

Concatenating strings / rows using dplyr, group_by & collapse or summarize, but maintain NA values

default arguments not being recognized in custom function using dplyr

R: Replacing NA values by mean of hour with dplyr

Is there a way to list values in na_if function in dplyr?

Using dplyr to replace negative values

Using dplyr in a for loop for multiple values

Using strptime on NA values

Nginx headers not recognized properly

How to properly return character values for dplyr's do?

Replace future dates with NA using dplyr

Replace NA with Zero in dplyr without using list()

Using dplyr summarise_each() with is.na()

Returning group maximum and NA using dplyr

Compute descriptive statistics (mean, sd, n) by a group column across multiple columns using lapply and dplyr resulting in NA values

replacing NA values using stringr

TOP Ranking

HotTag

Archive