1

Forgive me, but I have not been able to find an answer. I have some text-files organized like the one below, which I typeset into a table using pgfplotstable

\documentclass[border=1pt]{standalone}
\usepackage{pgfplotstable}
\pgfplotstableread{
no A B C D
1  2 3 4 3
2  nan nan nan 4
3  2 3 4 5
4  2 3 4 6
5  2 3 4 7
6  nan nan nan 8
7  2 3 4 9
}\datatable

\begin{document}
\pgfplotstabletypeset[header=true,columns={no,A,B,C}]\datatable
\end{document}

Is there any way I can skip the rows containing nan without hardcoding the skip? I guess the answer lies in row predicate/.code={} somewhere, but I am getting nowhere.

0

I feel stupid now. I managed to solve it after all.

    \documentclass[border=1pt]{standalone}
    \usepackage{pgfplotstable}
    \pgfplotstableread{
    no A B C D
    1  2 3 4 3
    2  nan nan nan 4
    3  2 3 4 5
    4  2 3 4 6
    5  2 3 4 7
    6  nan nan nan 8
    7  2 3 4 9
    }\datatable
    
    \begin{document}

\pgfplotstabletypeset[
col sep=tab,
header=true,
row predicate/.code={%
    \pgfplotstablegetelem{#1}{A}\of{\datatable}
    \pgfmathfloatparsenumber{\pgfplotsretval}
    \let\A=\pgfmathresult
    \pgfmathfloatgetflagstomacro\A\flags
    \ifnum\flags=3\relax\pgfplotstableuserowfalse
    \else\relax\fi}]{\datatable}
\end{document}

Does anyone know how I can define a command to skip the nan rows in the preamble?

I tried

\newcommand{skipnans}[3]{
row predicate/.code={%
    \pgfplotstablegetelem{#1}{#2}\of{#3}
    \pgfmathfloatparsenumber{\pgfplotsretval}
    \let\A=\pgfmathresult
    \pgfmathfloatgetflagstomacro\A\flags
    \ifnum\flags=3\relax\pgfplotstableuserowfalse
    \else\relax\fi}

Using \skipnans{#1,A,\datatable} gives an error of extra }'s

1
  • You can replace \else\relax\fi by just \fi. Jan 16 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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