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.