在R中将Excel文件列表动态转换为CSV文件 [英] Dynamically converting a list of Excel files to csv files in R

查看:241
本文介绍了在R中将Excel文件列表动态转换为CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个包含所有Excel(.xlsx)文件的文件夹,并且使用R我想使用"openxlsx"包(或某些版本)将所有这些文件自动转换为CSV文件.我目前有以下代码来转换文件之一并将其放置在同一文件夹中:convert("team_order\\team_1.xlsx", "team_order\\team_1.csv")

I currently have a folder containing all Excel (.xlsx) files, and using R I would like to automatically convert all of these files to CSV files using the "openxlsx" package (or some variation). I currently have the following code to convert one of the files and place it in the same folder:convert("team_order\\team_1.xlsx", "team_order\\team_1.csv")

我想自动执行此过程,以便对文件夹中的所有文件执行此过程,并删除当前的xlsx文件,因此仅保留csv文件.谢谢!

I would like to automate the process so it does it to all the files in the folder, and also removes the current xlsx files, so only the csv files remain. Thanks!

推荐答案

您可以使用

You can try this using rio, since it seems like that's what you're already using:

library("rio")
xls <- dir(pattern = "xlsx")
created <- mapply(convert, xls, gsub("xlsx", "csv", xls))
unlink(xls) # delete xlsx files

这篇关于在R中将Excel文件列表动态转换为CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆