R – how to use the exposition pipe %$% in purrr::map

For the purposes of this question, let’s split the mtcars dataset into several smaller ones, for example based on carb and store them all in a list mtlist <- group_split(mtcars, carb) Let’s now say that, only on one of these datasets, I am operating some pipeline and in the end I want to select a… Read More R – how to use the exposition pipe %$% in purrr::map

How to use `label_date_short`?

How I am using wrongly label_date_short from scales package? library(tidyverse) library(scales) date_taille <- tibble( Taille = rep(c("taille_hiver", "taille_ete"), times = 2), Date_taille = c("2016-08-01", "2016-02-01", "2018-08-01", "2018-02-01") %>% as.Date() ) ggplot(date_taille) + aes(x = Date_taille, y = Taille) + geom_point() + scale_x_date(date_breaks = "month", date_labels = label_date_short()) #or label_date() #> Error in format(x, format =… Read More How to use `label_date_short`?

Relative row index based on a variable value in R

wondering if there was an efficient and terse/concise data.table solution to the following problem. Please suppose that I have the following data.table: library(data.table) DT <- data.table(store = c("A", "A", "A", "A", "B", "B", "B", "B"), time = c(1,2,3,4,1,2,3,4), treat_time = c(0,0,1,0, 0,1,0,0)) Here, treat_time is the time period where the store receives a treatment. Note… Read More Relative row index based on a variable value in R