RStudio- split data with setting a seed

Your issue is likely due to incorrect indexing and the use of i++, which is not valid in R. Try this corrected version:

M_train_s_Sd <- list()
M_test_s_Sd <- list()

for (i in 1:length(Sd)) {
  set.seed(Sd[i])
  train_indices <- sample(nrow(mod_M), size = nrow(mod_M) * 0.7, replace = FALSE)
  M_train_s_Sd[[i]] <- mod_M[train_indices, ]
  M_test_s_Sd[[i]] <- mod_M[!mod_M$subject.id %in% M_train_s_Sd[[i]]$subject.id, ]
}

This ensures that M_train_s_Sd and M_test_s_Sd store the splits correctly in lists while fixing the indexing issue.