Math Avengers
Math Avengers

Reputation: 792

Why is the function work after doing fix() in R

Here's what had happened:

> NA.of.df = which(rowSums(is.na(df)) == ncol(df))
> NA.of.df 
named integer(0)
> fix(df) # i want to see what's in here -- nothing wrong
> NA.of.df # so i run it again  
1 3 5 7 9 # it works!

why would this happens??

A producible example (but doesn't seems like any data structure with dput()) is like the following:

> dput(NA.of.df)
structure(integer(0), .Names = character(0))

and NA.of.df is just the code for finding rows with all NAs (obtained from here: Remove rows in R matrix where all data is NA). (i.e. NA.of.df = which(rowSums(is.na(df)) == ncol(df)))

Upvotes: 2

Views: 82

Answers (1)

akrun
akrun

Reputation: 887991

It could be an issue with quotes around the NA resulting in is.na to not pick up those elements

is.na(c(NA, "NA"))
#[1]  TRUE FALSE

After doing the fix, it may have dropped the quotes and evaluate it correctly

Upvotes: 2

Related Questions