0

I have a couple txt files in a directory

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

and I want to create variables with the file names as names and read the corresponding files. How can I do this in R?

Thanks!

Seen
  • 4,054
  • 4
  • 37
  • 46

1 Answers1

6

You want list.files(), see it's help page at ?list.files. E.g.:

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"
Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453