I have a df with a columns date and observations. I want to delete all observations before the 2020-01-01. I decided to use while loop. Interestingly sometimes it works. But whenever I put it into function it does not work, returning "argument is of length zero"
subset1 <- data.frame("date"= c("2019-12-31", "2020-01-01", "2020-01-02", "2020-01-03"), "observations" = c(0,0,12,10))
while(subset1$date < "2020-01-01") {
subset1 = subset1[-1,]
}
What may be wrong?
Help is appreciated!!!