[Tex/LaTex] Add rows to a pgftable

pgfplotstable

I need to add a custom row of data to a \pgfplotstable for drawing purposes. The commented line is the needed data. I can read and manipulate any element from table but I can't add any row. Any advice ?

\documentclass{article}

\usepackage{pgfplots}

\begin{document}

\pgfplotstableread{
    s       f
    0.0     75.9638
    0.380665    206.565
    0.58711     243.435
    0.793555    333.435
%    1.0     Element(1,2) + 360.0 = 75.9638 + 360.0
}\data

\end{document}

Best Answer

You can add new rows to a pgfplotstable using \pgfplotstablevertcat, which takes two tables as arguments and concatenates the columns that are found in both tables:

\documentclass{article}

\usepackage{pgfplotstable}

\begin{document}

% Original data
\pgfplotstableread{
    0.0     75.9638
    0.380665    206.565
    0.58711     243.435
    0.793555    333.435
}\data

% Get column names
\pgfplotstablegetcolumnnamebyindex{0}\of{\data}\to{\firstcolumnname}
\pgfplotstablegetcolumnnamebyindex{1}\of{\data}\to{\secondcolumnname}

% Retrieve desired element
\pgfplotstablegetelem{1}{[index]1}\of\data

% Perform calculation, save to \result
\pgfmathsetmacro\result{\pgfplotsretval + 360}

% Assemble new line
\edef\createsumrow{\noexpand\pgfplotstableread[header=has colnames,col sep=comma,row sep=crcr]{
    \firstcolumnname,\secondcolumnname\noexpand\\
    1.0,\result\noexpand\\
}\sum}
\createsumrow

% Concatenate
\pgfplotstablevertcat{\data}{\sum}

% Output
\pgfplotstabletypeset{\data}

\end{document}