How do I separate the data by year for files that are listed in this way? How many in 2018 and how many in 2019? I'd appreciate it if you could tell me.
r
There is a method using the dplyr::count
function.
library(dplyr)
df = data.frame(
date = c(20100111, 20130517, 20130408, 20210123, 20210813, 20210927, 20160425)
)
df %>% mutate(year = substr(date, 1, 4)) %>% count(year)
output
year n
1 2010 1
2 2013 2
3 2016 1
4 2021 3
© 2024 OneMinuteCode. All rights reserved.