You've asked 3 questions, and I'll try to answer them all. As belisarius pointed out, Mathematica is case sensitive. So, your code should be:
In[1]:=ReadList["testA.txt", Number, RecordLists -> True]
However, this will still generate an error as your first line is made up of String
s not Number
s. So, the simplest thing to do is to go with Michael Pilat's solution and use Import
. This returns a list of lists where each record in the file becomes one of the sublists.
To access a specific sublist, you use Part
, or its simpler form [[ ]]
, as follows:
In[2]:={{100, 2010, 2, 20, 2010, 8, 30},
{110, 2010, 4, 30, 2010, 9,12},
{112, 2010, 8, 20, 2010, 10, 28}}[[1]]
Out[2]:={100, 2010, 2, 20, 2010, 8, 30}
Or, if you want a specific column
In[3]:={{100, 2010, 2, 20, 2010, 8, 30},
{110, 2010, 4, 30, 2010, 9,12},
{112, 2010, 8, 20, 2010, 10, 28}}[[All,4]]
Out[3]:={20, 30, 20}
Now, to add another column to your list, there are a couple of ways. The simplest way is to Transpose
your data,
In[4]:=Transpose[data]
Out[4]:={{100, 110, 112}, {2010, 2010, 2010}, {2, 4, 8},
{20, 30, 20}, {2010, 2010, 2010}, {8, 9, 10}, {30, 12, 28}}
select the now rows and Apply
the function to them,
In[5]:=Plus @@ Out[4][[{3,6}]]
Out[5]:={10,13,18}
attach the new row to the old data, and transpose back
In[6]:=Out[4]~Join~Out[5] // Transpose
Out[6]:={100, 2010, 2, 20, 2010, 8, 30, 10},
{110, 2010, 4, 30, 2010, 9, 12, 13},
{112, 2010, 8, 20, 2010, 10, 28, 18}}
A conceptually more difficult, but more straightforward method is to use Map
to apply a function to each row in the original data that returns the row with the new datum present
In[7]:=Map[#~Join~{Plus@@#[[{3,6}]]}&, data]
Out[7]:={100, 2010, 2, 20, 2010, 8, 30, 10},
{110, 2010, 4, 30, 2010, 9, 12, 13},
{112, 2010, 8, 20, 2010, 10, 28, 18}}