I have data set in a form ROG1.dat, ROG2.dat,...,ROG100.dat, I want to import all of them in Mathematica, Can you tell me how? Best
Asked
Active
Viewed 52 times
1 Answers
2
Try with:
SetDirectory["path to the directory with the data set"];
fileNames = "ROG" <> ToString@# <> ".dat" & /@ Range[100];
data = Import[#, "Data"] & /@ fileNames;
If in the folder there are just .dat files that you want to import, you can also use (edited after comment below):
data = AssociationMap[Import[#, "Data"] &, FileNames["*.dat"]]
Fraccalo
- 6,057
- 13
- 28
FileNamesaccepts glob operators for filenames, e.g.FileNames["*.dat"], soSelectis superfluous. Also, usingFileNameslike that will cause them to be listed in lexicographical order, e.g.In[90]:= FileNames["*.dat"] (*Out[90]= {"ROG10.dat", "ROG1.dat", "ROG20.dat", "ROG2.dat"}*). If you're running at least v10, I'd suggest usingAssociationMapinstead ofMap, then you can re-order at will. – rcollyer Aug 13 '18 at 19:47