r - 在 R 中。如何将文件夹中的多个文件从“旧名称”重命名为“新名称”,这些文件位于 CSV 文件的 2 列中。谢谢
问题描述
我正在尝试使用重命名功能并选择了正确的工作目录并使用 list.files 来获取旧名称,但不知道现在该做什么。我在 CSV 文件中有一个列,它与旧名称和新名称完全匹配:
PS。文件扩展名“.0”是 OPUS 光谱文件附带的。
old-name new-name
roth_666_1.0 N149_1.0
roth_666_2.0 N124_1.0
roth_666_3.0 N36_1.0
roth_666_4.0 N59_1.0
roth_666_5.0 N140_1.0
roth_666_6.0 N95_1.0
roth_666_7.0 N74_1.0
roth_666_8.0 N81_1.0
roth_666_9.0 N157_1.0
roth_666_10.0 N27_1.0
roth_666_11.0 N66_1.0
roth_666_12.0 N131_1.0
roth_666_13.0 N118_1.0
roth_666_14.0 N15_1.0
roth_666_15.0 N22_1.0
roth_666_16.0 N53_1.0
解决方案
因此,假设您有一个数据框 df,其中包含上述列“旧名称”和“新名称”,并假设当前工作目录是文件所在的位置:
# will not work due to hyphens in column names
# file.rename(from = df$old-name, to = df$new-name)
# better - specify the vector of values held in each column of the dataframe
file.rename(from = df[[1]], to = df[[2]] )
推荐阅读
- c - C中的临时对象
- reactjs - 如何在 App.js 中创建没有函数的 React.js 应用程序
- jquery - jQuery:第一次单击时未添加类,但适用于后续单击
- mysql - 基于 SQL 中的类别的第二个最大值
- python - 如何配置 Python 以便开始使用 aws-cli?
- python - 如何合并两个列表以找到最小重复因子?
- android - AppCenter:构建 React-Native 项目,它在 Git 中具有 2 层深度
- rest - REST 只能使用 HTTP 来实现,还是我们也可以使用其他东西?
- markdown - Laravel 电子邮件 Markdown 格式问题
- r - 如何从另一个有约束的数据帧聚合或计数?