Dear All, I am trying to run a function (growth over year) on each row of data.frame / data.table / tbl, since it is huge (1.5 million row). My main problem that it takes long time.

I am wondering if some one can help me in this issue, via using mutate in tidyverse, or by_row in purrrlyr, or any function in data.table.

```
#' ---
#' output:
#' md_document:
#' variant: markdown_github
#' ---
#+ reprex-setup, include = FALSE
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", error = TRUE)
knitr::opts_knit$set(upload.fun = knitr::imgur_upload)
knitr::opts_chunk$set(tidy = TRUE, tidy.opts = list(indent = 2))
#+ reprex-body
library(tidyverse)
library(purrrlyr)
library(reprex)
library(data.table)
growth.ls <- function(values, n = seq_along(values)){
# values <- as.numeric(values)
if (anyNA(values)) return(NA_real_)
if (any(!is.finite(values))) return(NA_real_)
if (any(values <= 0)) return(NA_real_)
# ln of y values then calculate regression line
z <- lm(log(values, base = exp(1))~(n))
# Exp of slope -1
(exp(z$coefficients[[2]]) - 1) * 100
}
set.seed(45L)
y <- data.table(x = sample(letters[1:10], 10^6, replace = TRUE),
x1 = sample(0.5:4, 10^6, replace = TRUE),
x2 = rnorm(10^6),
x3 = rnorm(10^6)
)
y %>% by_row(.collate = "rows", ..f = function(this_row){
this_row[2:4] %>% unlist %>% growth.ls})
```