I have a dataframe,df, with a date variable.
locationID organe
<int> <date>
1 1940-04-01
2 1938-07-01
3 1938-07-01
4 1938-07-01
I want to compare the dates with a fixed time point,like "1938-12-1", to find the earliest date. I used the min function but failed.
df %>% mutate(earliest=min(organe,as.Date("1938-12-1")))
locationID organe earliest
<int> <date> <date>
1 1940-04-01 1937-09-01
2 1938-07-01 1937-09-01
3 1938-07-01 1937-09-01
4 1938-07-01 1937-09-01
I don't know why min function does not work here, though it works well for the following situation
min(as.Date("1938-07-01"),as.Date("1938-12-1"))
[1] "1938-07-01"
Could anybody help?