Home > Back-end >  Unable to remove null values from dataframe in R
Unable to remove null values from dataframe in R

Time:09-26

I have a dataframe df containing 2 columns (State and Date). The State Columns has names of various states and the Date Column has NULL Values. I want to remove the rows containing these NULL values

I tried using multiple options like drop_na(), filter() and subset() using !is.null() but nothing seems to work. Can someone point out where am I going wrong.

mArkets <- market_data[c(1,4)]
mArkets <- mArkets %>% filter(!is.null(Date))

Thank you for your help.

Dataset Image

CodePudding user response:

They're not NULL at all, looks like they're '' (an empty string).

mArkets <- mArkets %>% filter(!is.null(Date) | Date!='')

would work.

CodePudding user response:

I feel that they might be empty strings:

mArkets <- mArkets[!is.null(mArkets$Date) && mArkets$Date != '']
  •  Tags:  
  • r
  • Related