Quantcast
Viewing all articles
Browse latest Browse all 205423

How to apply function over a list by taking list of list elements as function argument?

Reproduce-able data set-

set.seed(55)
data <- rnorm(8)

dates <- as.POSIXct("2019-03-18 10:30:00", tz = "CET") + 0:7*60
dataset <- xts(x = data, order.by = dates)

colnames(dataset) <- "R"
dataset$Timestep <- 1:8
dataset$Label <- 1
dataset$Label[4:8,] <- 2 

I am trying to fit linear regression model separately for each label by taking "R" as dependent variable and "timestamp" as predictor and return all the slopes ( in this case- 2).

Initially my thought was to use split and lapply function but could not manage to execute it as I don't know how to access list of list with lapply.

As the dataset is really large, I want to avoid for loop. Can you guys help? Really appreciate it.


Viewing all articles
Browse latest Browse all 205423

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>