Deleting a row in a dataframe

I currently have a dataframe of four columns and over 2,000 rows. Two of the columns contain many NA data points. I need to delete all the rows that contain the NA data point.

I am using my dataframe to eventually plot however, R says I cannot plot with the many NA points I have. So, deleting the rows would remove all NA data and the data point corresponding with the NA data. In other words, if my dataframe contains the row:
230 NA I will eventually be using the row as a point on a graph (230, NA). So, I need to not only delete the NA, but the 230 it corresponds to.

If you think of a better way to graph my data, please let me know. I am not an expert in Rstudio, so any teaching/explain is welcome.

I recommend you investigate the useful features of the tidyverse package. This is several useful libraries. One library focused on data manipulation is dplyr. The filter() function it provides is used to return rows that meet a condition. A condition might be to not have an NA in a column

I have tried, but when I use that particular function I get some kind of error.

Two things I have tried with this function is

filter(spo.data, spo.data$H2S_Sm >10)

Error in filter(spo.data, spo.data$H2S_Sm > 10) :
missing values in 'filter'

filter(spo.data, H2S_Sm <10)
Error in filter(spo.data, H2S_Sm <10) : object 'H2S_Sm' not found

spo.data is my data.frame and H2S_SM is my column which I want to filter out larger values than 10.

In relation to the code you shared, which libraries did you load.? Tidyverse? Dplyr?
If you did not load either, then probably stats::filter would be called and give you errors.

1 Like

I finally got it! I don't know what I did, but it did finally work.

Thank you for your help!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.