0

I am using R. Suppose I have the following data:

day_of_the_year = seq(as.Date("2010/1/1"), as.Date("2010/1/31"),by="day")
col_1 = rnorm(31,50,5)
col_2 = rnorm(31,100,5)

my_file = data.frame(day_of_the_year, col_1, col_2)

I am trying to learn how to keep rows and delete rows if a certain set of conditions is met, for example:

library(dplyr)

omit <- c("2010-01-12", "2010-01-16", "2010-01-20", "2010-01-25")

#keep rows if condition is met
final <- filter(my_file, !(day_of_the_year %in% omit | col_1 > 50 | col_2 >100))

#delete rows if condition is met
final <- filter(my_file, (day_of_the_year %in% omit | col_1 > 50 | col_2 >100))

Question: Is this the correct way to do this in R? Which other ways can this be done?

Thanks

stats_noob
  • 3,127
  • 2
  • 8
  • 27

0 Answers0