# TikZ: How to pass a specific table to \pgfplotstableset if used for tikzpicture

I have created the following code that appears to do what I want it to. Namely add an additional row to the table \IDA that is the average of four values. This row can then be used for a plot in tikzpicture.

\documentclass[tikz]{standalone}
\usepackage{filecontents}
\usepackage{pgfplots, pgfplotstable}

\begin{filecontents}{FileA.dat}
step ts1   ts2
1   3 4
2   7 6
3   4 6
4   5 6
5   5 7
6   9 3
\end{filecontents}

\begin{filecontents}{FileB.dat}
step  tHIws
1   3
2   7
3   4
4   5
5   5
6   9
\end{filecontents}

% for calculations
\pgfplotstableset{
create on use/tHIws/.style={
create col/expr={\thisrow{ts1}+\thisrow{ts2})/2}
}
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line=bottom,
axis y line=left,
tick align=outside,
xlabel=\texttt{step},
ylabel={$\theta_{a}$},
legend pos= north west,
legend columns=6,
legend style={fill=none, draw=none},
cycle multi list={
color list%
},
ymajorgrids,
]
[x=step, y=tHIws]
{\SST};
[x=step, y=tHIws]
{\IDA};
[x=step, y expr=(\thisrow{ts1}+\thisrow{ts2})/2]
{FileA.dat};
\end{axis}

\end{tikzpicture}
\end{document}


As I will however need to do this for a number of tables/figures I would like to somehow combine the two commands into one or at least make sure that the above \pgfplotstableset in only applied to the table \IDA.

Is there a way to do this?

Edited due to percusse's answer. I have actually tried to transfer that to tikxpictures but failed so far.

Edit 2: Full example!

Edit 3: Now with internal data. However I get an error on compiling: "Could not retrieve column 'step' from table 'FileA.dat'." But I can't seem to spot the error - I guess I am "Betriebsblind"

Edit 4: Added the missing usepackage for the inline file content

-
Hi I'm trying to understand the pgfplots issue a bit better. Would it be a fair solution if you would write [mymedian={ts1,ts2,ts3}] or should it be something else? My main difficulty in understanding is that what is being repeated over number of plots throughout the document, the mean calculation or the column names? – percusse May 18 '14 at 9:40
In my real document I don't only have FileA.dat and FileB.dat but rather about 50+ of them. All of them (which are like file A) have some columns I would like to have the average of (not the median). The columns all have the same names '(ts1, ..., tsN)'. As the averaging is the same for all tables I would like to have something that I can just apply to any of the tables and be sure what table I applied it to. As it is in my example I just use '\pgfplorstableset' after I have loaded a table and thats the one it is applied to. I would like to combine both into one action as to not mix it up. thx – MatoBehr May 18 '14 at 13:11

Regarding the edit, it is easier to place the experssion into a style and apply it whenever needed. Here I called it mymedian

\documentclass{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.10}
step ts1 ts2 ts3 ts4
1    3   4   11   14
2    7   6   22   26
3    4   6   34   31
4    5   6   45   46
5    5   7   55   57
6    9   3   69   63
}\SST

% for calculations
\pgfplotsset{mymedian/.style={
x=step, y expr=(\thisrow{ts1}+\thisrow{ts2}+\thisrow{ts3}+\thisrow{ts4})/4
}
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line=bottom,
axis y line=left,
tick align=outside,
xlabel=\texttt{step},
ylabel={$\theta_{a}$},
legend pos= north west,
legend columns=6,
legend style={fill=none, draw=none},
cycle multi list={
color list%
},
ymajorgrids,
]

@MatoBehr Can you include the whole example from documentclass to \end{document}? That saves us quite some time. – percusse May 8 '14 at 19:14