I am trying to write a for loop in R with a list of dataframes and path names For some reason,the second dataframe is the only one that exports. Any help would be greatly appreciated.
df1 <- data.frame(num = sample(1:10, 6, replace = TRUE), letter = sample(LETTERS[1:2], 6, replace =
TRUE))
df2 <- data.frame(num = sample(150:160, 6, replace = TRUE), letter = sample(LETTERS[1:2], 6, replace
= TRUE))
list_dfs <- list(df1,df2)
paths <- c("C:\\Export\\file1.csv","C:\\Export\\file2.csv")
for (i in 1:length(list_dfs)) {
for (f in 1:length(paths)) {
write.csv(list_dfs[i], file = paths[f], row.names = FALSE)
}
}