0

i'm making a for loop to creates and modifiy dataframes, and now i want to save them to my computer. I've tried with differents functions, but either way they don't save or just the last one is saved ( i have 66df). I'm new to R so maybe I'm missing something

my code looks like this

assign(paste0('output_df',sep = '_', i),df)
  
  write_csv(output_df, file = '/output/data frame.csv')

does the assign(past0 change something ? do you have any idea what's wrong ?

2
  • Because your output filename is the same. Read about paste. Try something like file = paste0("/output/dataframe_", i, ".csv") Commented Jun 21, 2022 at 10:21
  • thanks, i've tried this and it worked perfectly ! Commented Jun 21, 2022 at 11:56

1 Answer 1

1

The name of the data frame can remain the same, it is the name of the file that should be changed.

By the time it gets to write_csv(), the value of output_df should be different each time, but the name output_df can (and normally would) remain the same. And then you can save it with a different file name each time:

write_csv(output_df, file = paste0("/output/dataframe_", i, ".csv"))

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.