0

I have a dataset looking at infections. I want my final dataset to have both people who have infections and did not have infections. But remove those whose infections developed past 1 year. For example:

Infection 0 = No 1 = Yes (SSI) Time to Infection in Days(TTI)
0 NA
1 24
1 450

I am expecting this:

Infection 0 = No 1 = Yes (SSI) Time to Infection in Days(TTI)
0 NA
1 24

When I run

dt_one_year <- dt %>% filter(TTI %in% 0:365)

It removes both row 1 and row 3, when I want it to keep row 1 and 2. Any ideas how to do this using dplyr?

Remove only if SSI = 1 and TTI > 365.

divibisan
  • 11,659
  • 11
  • 40
  • 58

1 Answers1

0

Why not subset to rows that meet your criteria?

dt_one_year = subset(dt, dt$SSI == 0 & dt$TTI < 366)

Michael Dewar
  • 2,553
  • 1
  • 6
  • 22
enat_b
  • 28
  • 4