我正在使用write.csv写一堆数据帧:
data_frames <- Filter(function(x) is(x, "data.frame"), mget(ls()))
for (i in 1:length(data_frames)) {
file_name<- paste0("data/to_save/",names(data_frames[i]),".csv")
write.csv(data_frames[i], file = file_name, row.names = FALSE, col.names = TRUE)
}
问题是标题是乱码添加文件名到这样的每个colname(用记事本打开文件):
"April2016_file.customer_id","April2016_file.customerName","April2016_file.customerSurname".......
使用write.table
并使用来自包export
的{{1}}脚本的相同行为
必填结果:
rio
答案 0 :(得分:1)
我们需要使用list
提取[[
元素,因为[
仍为list
且data.frame
for (i in seq_along(data_frames)) {
file_name<- paste0("data/to_save/",names(data_frames[i]),".csv")
write.csv(data_frames[[i]], file = file_name, row.names = FALSE, col.names = TRUE)
}