How to exclude a part of a variable but not the NA?

Hello everyone, in this question my fate of having a good career position is dependent.plz help. I am beginner to R as well.

I have dataset pf 7147 observations. I need to exclude twins . In the twin variable I have 155twins, 32 Na and 6960 normal observations. So i run

data <- subset(m,F12v081==1)

this code to exclude 155 twins. So the result should be 6992 but the result gives me 6960 which means the code deleted the na. So plz help me how not to delete na.

Also for this code I need help
data <- subset(data,C6631B_hscrp <= 10)

I think the problem is because NA is not equal to 1 hence it is excluded. The solution is to include the NAs:

data <- subset(m,F12v081==1 |

I hope this (or something similar) helps.

1 Like

Another way, more intuitive for non-programmers is using the dplyr package:

data %>% filter(logical condition)

u can add as many logical conditions as you want filter by filter.

1 Like

It worked..thanks a lot Rolando..

Thanks this code worked as well.

This topic was automatically closed 7 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.