0

I'm new to R. I am trying to select all rows from a dataset where column x = y. Where y is an integer.

My code:

data_sub <- data_full[data_full$x == y,]

I am encountering a strange problem where the argument is returning the rows I asked for plus all rows in data_full where x = NA.

Has anyone encountered this before / could you explain it to me?

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
shrub
  • 3
  • 1
  • 3
  • you need to filter the `NA`s, do `df[df$x == y & !is.na(df$x),]` Or `na.omit(df[df$x == y, ])` Or `df[df$x == y & complete.cases(df), ]` – Ronak Shah Jun 04 '19 at 00:28

1 Answers1

0

You can use the dplyr package.

library(dplyr)
data_sub <- data_full %>% 
  dplyr::filter(x == y)

Or several other options.

Filter data.frame rows by a logical condition

bbiasi
  • 1,549
  • 2
  • 15
  • 31