2016-11-14 60 views
0

我想打開從遵循一致的序列網頁URL的多個文件內容如下:導入多個網頁文件

file001=read.table("https://...file_001.dat") 
file002=read.table("https://...file_002.dat") 
file003=read.table("https://...file_003.dat") 

我如何創建一段代碼,在打開多個連續的網頁文件像這樣的序列?

+0

?list.files將幫助你! –

+0

每個網頁文件都有一個共同的擴展名嗎? –

+0

是的,它們是上面列出的webfile_001,webfile_002等。 –

回答

0
path="/path/to/all_webfiles" 
x=list.files(path = path, pattern = ".dat") 
final_pathname = paste0(path, x) 

L=lapply(seq_along(final_pathname), function(i) read.table(final_pathname[i])) 

安置自己編輯的問題,

i <- 1:10 # assuming only 10 files 
l <- lapply(seq_along(i), function(j) read.table(paste0("http://file00", j))) 

這裏l將包含每個數據幀提供您的網站鏈接是正確的,作品!

+0

此解決方案暗示我已將web文件保存到某個目錄中的某個目錄嗎?我實際上是直接從網上獲取文件。 –

+0

@ DJ-AFC是否回答你的問題?注意遵循http://stackoverflow.com/help/someone-answers –