我一直在用这个扯掉我的头发。我正在尝试运行以下命令:
temp <- tempfile()
download.file("http://seanlahman.com/files/database/baseballdatabank-2017.1.zip", temp, mode="wb")
table1 <- unz(temp, "Salaries.csv")
salaries <- read.csv(table1, sep=",", header=T)
Run Code Online (Sandbox Code Playgroud)
但是,我认为它不起作用,因为我想要的实际文件(Salaries)位于名为“core”的文件夹中 - 我通过将压缩文件下载到我的计算机来查看结构。如何向此代码添加一些内容以查看核心文件夹并获取工资数据?如果可能,我想直接从 URL 执行此操作。谢谢!
您可以显式指定存档文件内的路径:
temp <- tempfile()
download.file("http://seanlahman.com/files/database/baseballdatabank-2017.1.zip", temp, mode="wb")
table1 <- unz(temp, "baseballdatabank-2017.1/core/Salaries.csv")
salaries <- read.csv(table1, sep=",", header=T)
Run Code Online (Sandbox Code Playgroud)