Patient01.txt <-scan("./Patient01.txt",what = "character") Patient02.txt <-scan("./Patient02.txt",what = "character") ... Patient130.txt <-scan("./Patient130.txt",what = "character")
有没有办法使用*应用程序自动化这个命令?
# read txt files with names of the form Patient*.txt txt_files = list.files(pattern = 'Patient*.txt'); # read txt files into a list (assuming separator is a comma) data_list = lapply(txt_files,read.table,sep = ",")
如果你知道它是什么,你可以改变分隔符.将数据保存为数据帧列表是方便的,因为它更容易投入向量化操作或稍后循环.