My df (first few rows...):
symbol date open high low close volume adjusted
1 ^GSPC 1930-01-02 21.2 21.2 21.2 21.2 0 21.2
2 ^GSPC 1930-01-03 21.2 21.2 21.2 21.2 0 21.2
3 ^GSPC 1930-01-06 21.5 21.5 21.5 21.5 0 21.5
4 ^GSPC 1930-01-07 21.3 21.3 21.3 21.3 0 21.3
5 ^GSPC 1930-01-08 21.3 21.3 21.3 21.3 0 21.3
6 ^GSPC 1930-01-09 21.6 21.6 21.6 21.6 0 21.6
7 ^GSPC 1930-01-10 21.5 21.5 21.5 21.5 0 21.5
8 ^GSPC 1930-01-13 21.5 21.5 21.5 21.5 0 21.5
9 ^GSPC 1930-01-14 21.6 21.6 21.6 21.6 0 21.6
10 ^GSPC 1930-01-15 21.6 21.6 21.6 21.6 0 21.6
My code:
df <- tq_get("^GSPC", from='1930-01-01', to='2022-12-31')
df %>% filter(yday(date) == 1)
==> does not work ... I get the following message: # A tibble: 0 x 8
# … with 8 variables: symbol , date , open , high , low , close ,
# volume , adjusted
# Use colnames()
to see all variable names
This code works for filtering:
df %>% filter(month(date) == 1, day(date) == 2)
When I change to day(date) == 1
it does not work.
I would like to just filter for the first day of each year.
Thank you for your help.