0

我在一个目录中有几个 txt 文件

dayton1.txt
datton2.txt
...
dakton50.txt

我想以文件名作为名称创建变量并读取相应的文件。我怎样才能在 R 中做到这一点?

谢谢!

4

1 回答 1

6

您想要list.files(),请参阅它的帮助页面?list.files。例如:

R> getwd()
 [1] "/blah/blah/packages/analogue/analogue/pkg"
R> list.files()
 [1] "data"         "DESCRIPTION"  "DESCRIPTION~" "inst"         "man"         
 [6] "NAMESPACE"    "NAMESPACE~"   "R"            "src"          "tests"       
[11] "vignettes"
R> list.files("./inst")
[1] "ChangeLog"  "ChangeLog~" "CITATION"   "CITATION~"  "COPYING"   
[6] "doc"        "THANKS"     "TODO"
于 2012-07-24T20:10:14.580 回答