delete Na values

Hey there,

I'm a bloody beginner with R Studio and need to analyze some data for my bachelor thesis. The thing is that I have kind of struggle with deleting some rows. I tried it with the function na.omit . Unfortunately, it deletes every data I have because there are a lot of Nas which have to be because of the design. I just need that the rows of the whole data are deleted if in the row of 10 specific columns is any NA. Does anybody have an idea how to handle this? Please help me I'm kind of desperate and that would save my thesis!

As a beginner to R you may benefit from studying this useful book.


Particularly chapter 5
and specifically section 5.2.3

Thank you ! that book seems pretty good for beginners! Do you have also any idea how to solve the problem in this case? I did not find any solution to this...

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

df <- tibble("a" = 2:10, 
       "b" = c(1:5, NA, NA, 8:9), 
       "c" = c(3:5, NA, 7:11), 
       "d" = c(51:58, NA))

df
# A tibble: 9 x 4
      a     b     c     d
  <int> <int> <int> <int>
1     2     1     3    51
2     3     2     4    52
3     4     3     5    53
4     5     4    NA    54
5     6     5     7    55
6     7    NA     8    56
7     8    NA     9    57
8     9     8    10    58
9    10     9    11    NA
# Drop row if NA in column b or c 
df %>% drop_na(b, c)
# A tibble: 6 x 4
      a     b     c     d
  <int> <int> <int> <int>
1     2     1     3    51
2     3     2     4    52
3     4     3     5    53
4     6     5     7    55
5     9     8    10    58
6    10     9    11    NA

Well, there is one example. Please ignore the ugly headers of the columns. I just need them like this for myself. The first column stands for those columns whose NA don't matter. I just need to delete a row if there is any NA in the last 4 columns.

Hello,
I'm sure you shared this image with the best intentions, but perhaps you didnt realise what it implies.
If someone wished to use example data to test code against, they would type it out from your screenshot...

This is very unlikely to happen, and so it reduces the likelihood you will receive the help you desire.
Therefore please see this guide on how to reprex data. Key to this is use of either datapasta, or dput() to share your data as code

I am really sorry, I really really tried my best but I didn't succeed. I can't paste the good looking tibble and the datapasta was a total mass. If you can not help me because of this formatting, I will hopefully find another solution. If there is any possibility to help me in this way, I would be really grateful!
You don't have to type it down. I'm just happy if you could give me any code and I will try it on my own.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.