0

I want to remove NA values created from missing data and remove ONLY the NAs and not delete the entire row

ex. I start with

           Big   Little   Small
           3     4        NA
           2     NA       NA
           3     NA       3
           2     2        2  

and I want to get:

          Big   Little   Small
           3     4    
           2          
           3             3
           2     2       2 
          

I do not want to remove the whole row with an NA, just the NA and have a blank there that wont be attributed into plots.

1 Answers1

0

The common solution to this is to save another data frame without the rows that include NA values that you then use for plotting. This will give you the desired outcome of plotting only the rows without NA, you'll just have to use a separate data frame or subset it when you plot it.

You can use the anyNA() function to return the values that are NA and then subset from that. For example if that row of your data frame is the first row you can get it by something like this:

# using df as main data frame
naValues = anyNA(df[1,])

dfNoNA = df
dfNoNA[1,] = dfNoNA[1,-naValues]

# use new df to plot
plot(dfNoNA$var1)

see documentation for anyNA() here, https://www.rdocumentation.org/packages/MaskJointDensity/versions/1.0/topics/anyNA

To