سؤال

I want to batch export data frames in my workspace having the string "obj" in their names to a csv file with the same name

I thought of the following code, which unfortunately does not work.

for (i in ls(pattern="obj")){
write.csv2(i, paste(i,".csv", sep=""))
}

Any ideas? Thank you in advance

هل كانت مفيدة؟

المحلول

write.csv2 takes the object rather than the name of the object as its first argument. Use get to remedy this.

write.csv2(get(i), paste(i,".csv", sep=""))

نصائح أخرى

You can do it with eval:

eval(call("write.csv2", as.name(i), paste(i, ".csv", sep="")))
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top