Search
 
SCRIPT & CODE EXAMPLE
 

R

Derive end of the week date in r

x <- seq(Sys.Date(), by = "1 day", length.out = 21)
data.frame(
  x = x,
  weekday = weekdays(x),
  next_friday = ceiling_date(x, "week") + 
    ifelse(weekdays(x) %in% c("Saturday", "Sunday"), 5, -2)
)
##              x   weekday next_friday
##  1  2014-11-17    Monday  2014-11-21
##  2  2014-11-18   Tuesday  2014-11-21
##  3  2014-11-19 Wednesday  2014-11-21
##  4  2014-11-20  Thursday  2014-11-21
##  5  2014-11-21    Friday  2014-11-21
##  6  2014-11-22  Saturday  2014-11-28
##  7  2014-11-23    Sunday  2014-11-28
##  8  2014-11-24    Monday  2014-11-28
##  9  2014-11-25   Tuesday  2014-11-28
##  10 2014-11-26 Wednesday  2014-11-28
##  11 2014-11-27  Thursday  2014-11-28
##  12 2014-11-28    Friday  2014-11-28
##  13 2014-11-29  Saturday  2014-12-05
##  14 2014-11-30    Sunday  2014-12-05
##  15 2014-12-01    Monday  2014-12-05
##  16 2014-12-02   Tuesday  2014-12-05
##  17 2014-12-03 Wednesday  2014-12-05
##  18 2014-12-04  Thursday  2014-12-05
##  19 2014-12-05    Friday  2014-12-05
##  20 2014-12-06  Saturday  2014-12-12
##  21 2014-12-07    Sunday  2014-12-12
Comment

PREVIOUS NEXT
Code Example
R :: r string split 
R :: R language get all columns in a dataset 
R :: r dot product 
R :: color code in R 
R :: r function to get class of all columns 
R :: r value statistics 
R :: ggplot categorical data r 
R :: calculated defualt values in R function parameters 
R :: empty environment r 
R :: generate pair with one same variable in r 
R :: logical vector passed in R 
R :: generate bin frequency table in R 
R :: r read.csv tab delimited 
R :: end the program in r 
R :: two letter country code in r 
R :: ggplot - subset top 10 in a stack bar plot 
R :: ways to examine model in r 
R :: concatenate r 
Rust :: cargo insall cargo-cahe this version of Cargo is older than the `2021` edition, and only supports `2015` and `2018` editions. 
Rust :: rust sleep 
Rust :: read file rust 
Rust :: rust•armanriazi•error•cannot be formatted using `{:?}` 
Rust :: rust variables in println 
Rust :: where in Rust 
Rust :: get function name rust 
Rust :: rust Pause execution for several seconds 
Rust :: rust•armanriazi•error•cannot be formatted with the default formatter 
Rust :: Rust Options Some None using closures 
Lua :: roblox check if player has gamepass 
Lua :: roblox send message script 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =