Message Boards Message Boards

0
|
3486 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Importing many single files and creating numbered (or indexed) variable?

Posted 2 years ago

I tried many different approaches, but I could not solve the following problems, I appreciate your help: What is the best way to import many data files and names this files?

Attachments:
3 Replies
Posted 2 years ago

Hi Luis,

Not sure what you mean by

What is the best way to import many data files and names this files

I assume you want to have the symbols generated in dd to be set to the contents of the corresponding file.

Is there a reason to hardcode the Range? Why not Range@Length@names?

dd = Symbol /@ ("data" <> ToString[#] & /@ Range[325])

Then

MapThread[(#1 = #2) &, {dd, allData}]
POSTED BY: Rohit Namjoshi

Thank you very much, you helped me solve the problem.

Posted 2 years ago

You are welcome.

Rather than setting individual symbols to the content of a file you might want to consider using an Association / Dataset instead. If you do data analysis that requires data from multiple files then using individual symbols is very cumbersome and error prone. One way to do this

data = AssociationMap[Import, names] // Dataset

The keys are the file names (much better than data1, data2, ...) and the values are the content of the corresponding file.

POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract