I'm trying to automate some analysis for the company where I'm working and I need to check if the data in each row was created in April or not. As a pretty much complete beginner with R, this is no easy task for me. The date is a string presented as follows:
01-Apr-2017 12:34:56
To create a data frame with only observations from April 2017 in them, I am trying to use subset. My code is as follows:
df2=subset(df,identical(substr(Closed,4,11),"Apr-2017"))
When I run this, it gives me a new data frame with 0 rows, which indicates to me that it never found an example in the factor Closed in which characters 4-11 were equal to Apr 2017
. However, when I manually use a row that has this date, it returns TRUE
just as would be necessary in the subset function:
dats.gmdm$Closed[131] #This returns "14-Apr-2017 14:39:28"
substr(dats.gmdm$Closed[131],4,11) #This returns "Apr-2017"
identical(substr(dats.gmdm$Closed[131],4,11),"Apr-2017") #And this returns TRUE
Theoretically, I should have a set with only these instances, but it just gives me an empty data frame with 22 factors (same as in the original dataset).
Is there another way to do this, or how is my code wrong? If not, why is it not theoretically possible?