Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
gogonzo committed Apr 26, 2020
1 parent 62583cc commit 52de26c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
28 changes: 27 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ runner(
)
```


### `NA` padding
Using `runner` one can also specify `na_pad = TRUE` which would return `NA` for
any window which is partially out of range - meaning that there is no sufficient
Expand All @@ -179,6 +178,33 @@ runner(
)
```

### Using runner with `data.frame`

User can also put `data.frame` into `x` argument and apply functions which involve
multiple columns. In example below we calculate beta parameter of `lm` model on
1, 2, ..., n observations respectively. On the plot one can observe how `lm`
parameter adapt with increasing number of observation.

```{r eval=FALSE}
date <- Sys.Date() + cumsum(sample(1:3, 40, replace = TRUE)) # unequaly spaced time series
x <- cumsum(rnorm(40))
y <- 30 * x + rnorm(40)
df <- data.frame(date, y, x)
slope <- runner(
df,
k = 10,
idx = "date",
function(x) {
coefficients(lm(y ~ x, data = x))[2]
}
)
plot(slope)
abline(h = 30, col = "blue")
```

### Build-in functions
With `runner` one can use any R functions, but some of them are optimized for
speed reasons.
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,34 @@ runner(
)
```

### Using runner with `data.frame`

User can also put `data.frame` into `x` argument and apply functions
which involve multiple columns. In example below we calculate beta
parameter of `lm` model on 1, 2, …, n observations respectively. On the
plot one can observe how `lm` parameter adapt with increasing number of
observation.

``` r
date <- Sys.Date() + cumsum(sample(1:3, 40, replace = TRUE)) # unequaly spaced time series
x <- cumsum(rnorm(40))
y <- 30 * x + rnorm(40)

df <- data.frame(date, y, x)

slope <- runner(
df,
k = 10,
idx = "date",
function(x) {
coefficients(lm(y ~ x, data = x))[2]
}
)

plot(slope)
abline(h = 30, col = "blue")
```

### Build-in functions

With `runner` one can use any R functions, but some of them are
Expand Down

0 comments on commit 52de26c

Please sign in to comment.