I would appreciate it if you could let me know R studio annual data extraction.

Asked 1 years ago, Updated 1 years ago, 364 views

이미지 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

2023-01-31 12:02

1 Answers

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


2023-01-31 16:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.