[英]Read files with a specific a extension from a folder in R
我想使用函數 read.table 讀取擴展名為 .output 的文件。 我使用了 pattern=".output" 但它不正確。 有什么建議?
例如,這里是如何讀取擴展名為“.output”的文件並創建表列表
list.filenames <- list.files(pattern="\\.output$")
trialsdata <- lapply(list.filenames,read.table,sep="\t")
或者如果您只想手動一次讀取它們,只需在文件名參數中包含擴展名。
read.table("ACF.output",sep=...)
所以最后因為我沒有找到解決方案(我的路徑出了問題)我制作了一個文本文件,其中包含所有 .output 文件ls *.output > data.txt
。 之后使用:
files = read.table("./data.txt")
我正在制作一個包含我所有文件的 data.frame 並使用
files[] <- lapply(files, as.character)
最后使用test = read.table(files[i,],header=F,row.names=1)
我們可以讀取存儲在 i 中的每個文件(i = no of line)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.