diff --git a/404.html b/404.html index 96244be..9a28c17 100644 --- a/404.html +++ b/404.html @@ -38,7 +38,7 @@ runner - 0.4.2 + 0.4.4 @@ -112,7 +112,7 @@

Page not found (404)

-

Site built with pkgdown 2.0.6.

+

Site built with pkgdown 2.0.7.

diff --git a/articles/apply_any_r_function.html b/articles/apply_any_r_function.html index f47d606..7718be2 100644 --- a/articles/apply_any_r_function.html +++ b/articles/apply_any_r_function.html @@ -39,7 +39,7 @@ runner - 0.4.2 + 0.4.4 @@ -91,9 +91,10 @@
##       x   f1 f2   f3
 ## 1  <NA> <NA>  b <NA>
 ## 2  <NA> <NA>  b <NA>
@@ -241,15 +308,25 @@ 

Filling missing values

Running which

-

To obtain index number of element matching some condition in window, one can use which_run, which returns index of TRUE element appeared before n-th element of a vector. If na_rm = TRUE is specified, missing is treated as FALSE, and is ignored while searching for TRUE. While user set na_rm = FALSE like in second example, function returns NA, because in following window TRUE appears after missing and it’s impossible to be certain which is first (missing is an element of unknown value - could be TRUE or FALSE).

+

To obtain index number of element matching some condition in window, +one can use which_run, which returns index of +TRUE element appeared before n-th element of a vector. If +na_rm = TRUE is specified, missing is treated as +FALSE, and is ignored while searching for +TRUE. While user set na_rm = FALSE like in +second example, function returns NA, because in following +window TRUE appears after missing and it’s impossible to be +certain which is first (missing is an element of unknown value - could +be TRUE or FALSE).

 x <- c(T, T, T, F, NA, T, F, NA, T, F, T, F)
 data.frame(
-  x, 
+  x,
   s0 = which_run(x, which = "first"),
   s1 = which_run(x, na_rm = FALSE, k = 5, which = "first"),
-  s2 = which_run(x, k = 5, which = "last"))
+ s2 = which_run(x, k = 5, which = "last") +)

##        x s0 s1 s2
 ## 1   TRUE  1  1  1
 ## 2   TRUE  1  1  2
@@ -263,7 +340,12 @@ 

Running which## 10 FALSE 1 6 9 ## 11 TRUE 1 NA 11 ## 12 FALSE 1 NA 11

-

which argument (‘first’ or ‘last’) used with which_run determines which index of matching element should be returned from window. In below illustration in k = 4 elements window there are two TRUE values, and depending on which argument output is equal 2 or 4.

+

which argument (‘first’ or ‘last’) used with +which_run determines which index of matching element should +be returned from window. In below illustration in k = 4 +elements window there are two TRUE values, and depending on +which argument output is equal 2 or +4.

@@ -286,7 +368,7 @@

Running which

-

Site built with pkgdown 2.0.6.

+

Site built with pkgdown 2.0.7.

diff --git a/articles/index.html b/articles/index.html index f0a6026..3454cbb 100644 --- a/articles/index.html +++ b/articles/index.html @@ -23,7 +23,7 @@ runner - 0.4.2 + 0.4.4 @@ -88,7 +88,7 @@

All vignettes

-

Site built with pkgdown 2.0.6.

+

Site built with pkgdown 2.0.7.

diff --git a/articles/runner_examples.html b/articles/runner_examples.html index 18e02ba..e0b0698 100644 --- a/articles/runner_examples.html +++ b/articles/runner_examples.html @@ -39,7 +39,7 @@ runner - 0.4.2 + 0.4.4 @@ -100,7 +100,11 @@

Runner examples

-

The most fundamental function in runner package is runner. With runner::runner one can apply any R function on running windows. This tutorial presents set of examples explaining how to tackle some tasks. Some of the examples are referenced to original topic on stack-overflow.

+

The most fundamental function in runner package is +runner. With runner::runner one can apply any +R function on running windows. This tutorial presents set of examples +explaining how to tackle some tasks. Some of the examples are referenced +to original topic on stack-overflow.

Number of unique elements in 7 days window

@@ -111,9 +115,9 @@

Number of unique elements in date <- Sys.Date() + cumsum(sample(1:5, 20, replace = TRUE)) # unequally spaced time series runner( - x, + x, k = "7 days", - idx = date, + idx = date, f = function(x) length(unique(x)) )

@@ -127,9 +131,9 @@

weekly trimmed meandate <- Sys.Date() + cumsum(sample(1:5, 20, replace = TRUE)) # unequaly spaced time series runner( - x, - k = "week", - idx = date, + x, + k = "week", + idx = date, f = function(x) mean(x, trim = 0.05) ) @@ -142,8 +146,8 @@

Predict # sample data x <- cumsum(rnorm(20)) data <- data.frame( - date = Sys.Date() + cumsum(sample(1:3, 20, replace = TRUE)), # unequally spaced time series, - y = 3 * x + rnorm(20), + date = Sys.Date() + cumsum(sample(1:3, 20, replace = TRUE)), # unequally spaced time series, + y = 3 * x + rnorm(20), x = cumsum(rnorm(20)) ) @@ -167,7 +171,8 @@

Predict

Rolling sums for groups with uneven time gaps

-

SO discussion

+

SO +discussion

 library(runner)
 library(dplyr)
@@ -175,9 +180,12 @@ 

Rolling sums for groups w set.seed(3737) df <- data.frame( user_id = c(rep(27, 7), rep(11, 7)), - date = as.Date(rep(c('2016-01-01', '2016-01-03', '2016-01-05', '2016-01-07', - '2016-01-10', '2016-01-14', '2016-01-16'), 2)), - value = round(rnorm(14, 15, 5), 1)) + date = as.Date(rep(c( + "2016-01-01", "2016-01-03", "2016-01-05", "2016-01-07", + "2016-01-10", "2016-01-14", "2016-01-16" + ), 2)), + value = round(rnorm(14, 15, 5), 1) +) df %>% group_by(user_id) %>% @@ -192,7 +200,8 @@

runner with dplyr

Unique for specified time frame

-

SO discussion

+

SO +discussion

 library(runner)
 library(dplyr)
@@ -216,14 +225,16 @@ 

Unique for specified time framedf %>% group_by(user_id) %>% mutate( - distinct_7 = runner(category, - k = "7 days", - idx = as.Date(date), - f = function(x) length(unique(x))), - distinct_14 = runner(category, - k = "14 days", - idx = as.Date(date), - f = function(x) length(unique(x))) + distinct_7 = runner(category, + k = "7 days", + idx = as.Date(date), + f = function(x) length(unique(x)) + ), + distinct_14 = runner(category, + k = "14 days", + idx = as.Date(date), + f = function(x) length(unique(x)) + ) )

@@ -235,7 +246,7 @@

runner with group_by mutatex <- cumsum(rnorm(20)) y <- 3 * x + rnorm(20) date <- Sys.Date() + cumsum(sample(1:3, 20, replace = TRUE)) # unequaly spaced time series -group <- rep(c("a", "b"), each = 10) +group <- rep(c("a", "b"), each = 10) data.frame(date, group, y, x) %>% @@ -243,13 +254,13 @@

runner with group_by mutaterun_by(idx = "date", k = "5 days") %>% mutate( alpha_5 = runner( - x = ., + x = ., f = function(x) { coefficients(lm(x ~ y, x))[1] } ), beta_5 = runner( - x = ., + x = ., f = function(x) { coefficients(lm(x ~ y, x))[1] } @@ -257,41 +268,47 @@

runner with group_by mutate)

-

Aggregating values from another data.frame in grouped_df +

Aggregating values from another data.frame in +grouped_df

-

SO Discussion

+

SO +Discussion

 library(runner)
 library(dplyr)
 
-Date <- seq(from = as.Date("2014-01-01"), 
-            to = as.Date("2019-12-31"), 
-            by = 'day')
+Date <- seq(
+  from = as.Date("2014-01-01"),
+  to = as.Date("2019-12-31"),
+  by = "day"
+)
 market_return <- c(rnorm(2191))
 
 AAPL <- data.frame(
-  Company.name = "AAPL", 
-  Date =  Date,
+  Company.name = "AAPL",
+  Date = Date,
   market_return = market_return
 )
 
 MSFT <- data.frame(
-  Company.name = "MSFT", 
+  Company.name = "MSFT",
   Date = Date,
   market_return = market_return
 )
 
 df <- rbind(AAPL, MSFT)
 df$stock_return <- c(rnorm(4382))
-df <- df[order(df$Date),]
+df <- df[order(df$Date), ]
 
 df2 <- data.frame(
-  Company.name2 = c(replicate(450, "AAPL"), replicate(450, "MSFT")), 
+  Company.name2 = c(replicate(450, "AAPL"), replicate(450, "MSFT")),
   Event_date = sample(
-    seq(as.Date('2015/01/01'), 
-        as.Date('2019/12/31'), 
-        by = "day"),
-    size =  900)
+    seq(as.Date("2015/01/01"),
+      as.Date("2019/12/31"),
+      by = "day"
+    ),
+    size = 900
+  )
 )
 
 
@@ -299,8 +316,8 @@ 

Aggregating va group_by(Company.name2) %>% mutate( intercept = runner( - x = df[df$Company.name == Company.name2[1], ], - k = "180 days", + x = df[df$Company.name == Company.name2[1], ], + k = "180 days", lag = "5 days", idx = df$Date[df$Company.name == Company.name2[1]], at = Event_date, @@ -311,8 +328,8 @@

Aggregating va } ), slope = runner( - x = df[df$Company.name == Company.name2[1], ], - k = "180 days", + x = df[df$Company.name == Company.name2[1], ], + k = "180 days", lag = "5 days", idx = df$Date[df$Company.name == Company.name2[1]], at = Event_date, @@ -344,7 +361,7 @@

Aggregating va

-

Site built with pkgdown 2.0.6.

+

Site built with pkgdown 2.0.7.

diff --git a/authors.html b/authors.html index 09e1ee6..2a72303 100644 --- a/authors.html +++ b/authors.html @@ -23,7 +23,7 @@ runner - 0.4.2 + 0.4.4

@@ -83,15 +83,15 @@

Citation

-

Kałędkowski D (2022). +

Kałędkowski D (2024). runner: Running Operations for Vectors. -R package version 0.4.2. +R package version 0.4.4.

@Manual{,
   title = {runner: Running Operations for Vectors},
   author = {Dawid Kałędkowski},
-  year = {2022},
-  note = {R package version 0.4.2},
+  year = {2024},
+  note = {R package version 0.4.4},
 }
@@ -105,7 +105,7 @@

Citation

-

Site built with pkgdown 2.0.6.

+

Site built with pkgdown 2.0.7.

diff --git a/index.html b/index.html index b8e0470..be8f529 100644 --- a/index.html +++ b/index.html @@ -42,7 +42,7 @@ runner - 0.4.2 + 0.4.4 @@ -93,14 +93,17 @@
-
+

+

About

@@ -128,10 +131,10 @@

Using runner) runner( - x, + x, lag = "1 months", - k = "4 months", - idx = x$date, + k = "4 months", + idx = x$date, f = function(x) { cor(x$a, x$b) } @@ -158,8 +161,8 @@

Window lag

 runner(
-  1:15, 
-  k = 4, 
+  1:15,
+  k = 4,
   lag = 2
 )

@@ -171,9 +174,9 @@

Windows depending on date
 idx <- Sys.Date() + c(4, 6, 7, 13, 17, 18, 18, 21, 27, 31, 37, 42, 44, 47, 48)
 runner(
-  x = 1:15, 
-  k = "5 days", 
-  lag = "1 days", 
+  x = 1:15,
+  k = "5 days",
+  lag = "1 days",
   idx = idx
 )

@@ -185,10 +188,10 @@

Running at
 idx <- c(4, 6, 7, 13, 17, 18, 18, 21, 27, 31, 37, 42, 44, 47, 48)
 runner(
-  x = idx, 
-  k = 5, 
-  lag = 1, 
-  idx = idx, 
+  x = idx,
+  k = 5,
+  lag = 1,
+  idx = idx,
   at = c(18, 27, 48, 31)
 )

@@ -201,10 +204,10 @@

 idx <- c(4, 6, 7, 13, 17, 18, 18, 21, 27, 31, 37, 42, 44, 47, 48)
 runner(
-  x = idx, 
-  k = 5, 
-  lag = 1, 
-  idx = idx, 
+  x = idx,
+  k = 5,
+  lag = 1,
+  idx = idx,
   at = c(4, 18, 48, 51),
   na_pad = TRUE
 )
@@ -240,7 +243,7 @@

Parallel computation
 library(parallel)
 
-# 
+#
 numCores <- detectCores()
 cl <- makeForkCluster(numCores)
 
@@ -301,10 +304,8 @@ 

Developers

Dev status

    -
  • Check
  • +
  • Check
  • -
  • -
  • Dependencies
@@ -320,7 +321,7 @@

Dev status

-

Site built with pkgdown 2.0.6.

+

Site built with pkgdown 2.0.7.

diff --git a/news/index.html b/news/index.html index b28f7aa..cf12a1c 100644 --- a/news/index.html +++ b/news/index.html @@ -23,7 +23,7 @@ runner - 0.4.2 + 0.4.4 @@ -70,7 +70,11 @@

Changelog

- + +
  • fix an example after dependency change.
  • +
+
+
  • fix runner(..., na_pad) for vectors to return NA when windows is incomplete. Other methods already consistent.
  • fix the problems when calling runner::runner using do.call. (#83 and #84)
@@ -120,7 +124,8 @@