Using R, I wanted to save each variable's value when running lapply().
Below is what I tested now:
list_C <- list()
list_D <- list()
n <- 1
data_partition <- split(data, with(data, paste(A, B, sep=":")))
final_result <- lapply(data_partition,
                       function(dat) {
                         if(... condition ...) {
                           <Some R codes to run>
                           list_C[[n]] <- dat$C
                           list_D[[n]] <- dat$D
                           n <- n + 1
                         }
                       })
However, after running the code, 'n' remains just '1' and there's no change. How can I change the variable of 'n' to get the right saving lists of 'list_C' and 'list_D'?
