In "for" repeat sentence, how to write separate csv files with different name in each turn?

Hi, neighbors!

Is there any way to write csv with different names in "for" sentence?
What I'm trying to do is make different csv files for each crop.

my code is as below

crops <- c(cocoa, coffee, maize, rice, potato, tobacco, tea, wheat) #all are dataframes

str(cocoa)
'data.frame': 292 obs. of 21 variables

mg <- NULL
for(i in crops){
mg <- merge(x=i, y=gdp, by.x="Label", by.y="Country name", all.x=true)
write.csv(mg, "i plus")
}

Thank you for your help in advance.

lets start at the top. assuming you have data.frames named cocoa, coffee , maize etc.
do you want to turn them into a big list called crops where each entry is a column from the frames you had ? or do you rather want crops to be a list of the exact data.frames ? if the latter use list() rather than c()

example

x <- c(iris,mtcars)
str(x)
y <- list(iris,mtcars)
str(y)

This topic was automatically closed 21 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.