重新创建文件扩展名以便轻松加载到R

时间:2018-10-02 18:39:52

标签: r

我试图读取多个数据集(大约300个),这些数据集的名称与以下名称相似(我没有同时加载所有数据集,但是我试图找到一种通用的解决方案,其中我只更改了R文件开头的几件事)

E:/Data/Academic/Year1/External/beer/beer_drug_1114_1165
E:/Data/Academic/Year1/External/beer/beer_groc_1114_1165

E:/Data/Academic/Year1/External/beer/beer_PANEL_DR_1114_1165.dat
E:/Data/Academic/Year1/External/beer/beer_PANEL_GR_1114_1165.dat
E:/Data/Academic/Year1/External/beer/beer_PANEL_MA_1114_1165
E:/Data/Academic/Year1/External/beer/Delivery_Stores

唯一改变的是

Year1E:/Data/Academic/Year1/External

beerbeer/beer_drug_1114_1165

1114_1165的末尾和扩展名

因此,我尝试使用paste0的不同组合以重新创建文件扩展名。

我有类似下面这样的东西,效果不佳。

file <- "E:/IRI Data/Academic Dataset External/Year1/External/"
product <- "/beer"
weeks <- "_1114_1165"

paste0(file, product, product, weeks)

但是我想在扩展名的中间更改/ Year1/。

扩展名:

drug <- read.table("E:/Data/Academic/Year1/External/beer/beer_drug_1114_1165", header = TRUE)
groc <- read.table("E:/Data/Academic/Year1/External/beer/beer_groc_1114_1165", header = TRUE)


PANEL_DR <- read.delim("E:/Data/Academic/Year1/External/beer/beer_PANEL_DR_1114_1165.dat", header = TRUE)
PANEL_GR <- read.delim("E:/Data/Academic/Year1/External/beer/beer_PANEL_GR_1114_1165.dat", header = TRUE)
PANEL_MA <- read.delim("E:/Data/Academic/Year1/External/beer/beer_PANEL_MA_1114_1165.dat", header = TRUE)


Delivery_Stores <- read.fwf("E:/Data/Academic/Year1/External/beer/Delivery_Stores",
                            widths = c(7, 3, 9, 21, 5, 4, 5, 9))

0 个答案:

没有答案