Save several csv files from an array

Hi,

I have an array has a dimension = c(6L, 6L, 181L)

I want to write 181 CSV files for each matrix in the array by using for-Loop and give the csv files specific names for example result1.csv ,,, result181.csv .

Any advice will be highly appreciated.

write_out <- function(x) write.csv(the_array[x,,],file = the_files[x])
the_path  <- getwd()
the_names <- paste0("result",1:181,".csv")
the_files <- paste0(the_path,"/",the_names)
the_array <- array(sample(1:6516,6516), c(181,6,6))
for(i in 1:181) write_out(i)

Created on 2023-03-07 with reprex v2.0.2

For an undetermined reason the preferred form

for(i in seq_along(the_array)) ...

throws an error by attempting a 182nd iteration.

thank you very much!

The reason seq_along(the_array) doesn't work is that length(the_array) is 6516.

1 Like

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.