Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some problems with importing a .txt file as a table. This is the file. I tried importing it with

data = Import["data.txt", "Data"] 

I want to access single values, but it doesn't work with my import. I can't access data[[2, 1]] for example to get the first value in data[[2]] and so on. Any ideas?

share|improve this question
up vote 5 down vote accepted
xxx = Import["C:\\Users\\Rasher\\Downloads\\data.txt", "Data"];
zzz = xxx // StringSplit;
zzz[[2, 2]]

Gives 774...

You need to decide how / where to "split" or do other operations, since this is basically a bulk text file, e.g., split at line-breaks, etc. Read the documentation on StringSplit and ancillary text manipulation functions, once you've imported it these will let you massage it into the desired MMA list/array structure.

With just the above, row 1 of zzz is what appear to be the column headings, so zzz[[1,n]] gets you the n'th one. Row 2 to ... are the rows, with the first entry the row name, e.g, zzz[[2,1]] gets the name of the first row under headings, zzz[[2,2]] the first row entry, etc.

share|improve this answer
Ahh StringSplit, of course. Works fine now..thanks :) – holistic Feb 27 '14 at 11:59

Here is another way that does it for you in one go:

data = ReadList["", Word,
               RecordLists -> True];

So that:

data[[2, 2]]

gives 774

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.