-2

I would like to write each row of a matrix in a separate csv file, which has a specific name for itself?

  • When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. How do you want to name these files? – MrFlick Apr 27 '19 at 16:27

1 Answers1

2

Solution using sapply

set.seed(3)
my_matrix <- matrix(rnorm(400),nrow = 20) ##Create fake data

sapply(1:20,function(i)write.csv(my_matrix[i,],
                                 paste0("my_matrix_row_",i,".csv"),
                                 row.names = FALSE)) ##Sapply to write
Henry Cyranka
  • 2,970
  • 1
  • 16
  • 21