grep: How can i search through my data using a wildcard

#1
Hey everyone. I have recently started using R. So now I am trying to get some data out of it. However, the results I get are quite confusing. I have datas from the year 1961 to 1963 of everyday in the format 1961-04-25. I created a vector called: date

So when I try to use grep to just search for the period between April 10 and May 21 and display the dates I used this command:

> date[date>=grep("196.-04-10", date, value = TRUE) & date<=grep("196.-05-21", date, value = TRUE)]

The results I get is are somehow confusing as it is making 3 days steps instead of giving me every single day... see below.


[1] "1961-04-10" "1961-04-13" "1961-04-16" "1961-04-19" "1961-04-22" "1961-04-25" "1961-04-28" "1961-05-01" "1961-05-04" "1961-05-07" "1961-05-10"
[12] "1961-05-13" "1961-05-16" "1961-05-19" "1962-04-12" "1962-04-15" "1962-04-18" "1962-04-21" "1962-04-24" "1962-04-27" "1962-04-30" "1962-05-03"
[23] "1962-05-06" "1962-05-09" "1962-05-12" "1962-05-15" "1962-05-18" "1962-05-21" "1963-04-11" "1963-04-14" "1963-04-17" "1963-04-20" "1963-04-23"
[34] "1963-04-26" "1963-04-29" "1963-05-02" "1963-05-05" "1963-05-08" "1963-05-11" "1963-05-14" "1963-05-17" "1963-05-20"

Can anyone help me with this
 

Dason

Ambassador to the humans
#2
It would probably be better to work with an actual date object for what you want to do.

Not based on your code but here is some example use of Dates in R
Code:
nov1 <- as.Date("11-1-2012", format = "%m-%d-%Y")
dates <- seq(nov1, Sys.Date(), by = "day")
mybirthday <- as.Date("11-13-2012", format = "%m-%d-%Y")
dates[dates <= mybirthday]
 
#3
Hey Dason,

thanks for the answer, but somehow it doesnt lead me to get the dates of all the years I need. Maybe its bc I am a beginner, but I already converted my vector to an actual date format, however, I somehow need a wildcard so it gives me all the years needed.