79703111

Date: 2025-07-16 08:19:40
Score: 0.5
Natty:
Report link

I had restarted R and R sessions many times at first, still got the same results. But two days later, I re-ran the program, and got very different results. The isoweek() is much faster than strftime() this time, althought still much slower than {clock} package. Don't know what happened. But I'm glad the problem is solved. So I'm using {clock} package for my program.

library(lubridate)
library(dplyr)
library(clock)

system.time({
  sim_data |> 
    mutate(week_base = strftime(dates, format = "%V"))
})
# user  system elapsed 
# 3.00    0.02    3.04

system.time({
  sim_data |> 
    mutate(week = isoweek(dates))
})
# user  system elapsed 
# 0.56    0.03    0.60 

system.time({
  sim_data |> 
    mutate(isoweek = get_week(as_iso_year_week_day(dates)))
})
# user  system elapsed 
# 0.05    0.02    0.09
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: JohnYoung