I created a mutiple dimension array called, decision, and I want to output the array into csv files, e.g. decision[,,1]
; decision[,,2]
; ...; decision[,,36]
into different files, can I use some function to output them in one time?
instead of using
write.csv(decision[,,1],file="data1.csv")
write.csv(decision[,,36],file="data36.csv")
Solution using purrr
:
library(purrr)
# example data
decision <- array(runif(10 * 5 * 4), dim = c(10, 5, 4))
purrr::walk(1:dim(decision)[3], ~ write.csv(arr[,,.x], file = paste0("data", .x, ".csv"), row.names = FALSE))