6

Question: I am trying to select certain rows, similar to this question Selecting rows to be displayed with pgfplotstable, however I am not sure how I would go about doing it. I want to display only every 4th row. Something like skip rows between index but more automated than that (the file is fairly long). I have attempted to use the code below code, but I am at a loss as to how I would output only every 4th row (starting from 1 (ie: 1, 5, 9, etc). I assume some type of math operator would work, but how?

\documentclass{standalone}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstableread{
 obs      number
  1         2
  2         5
  3         3
  4         2
  5         4
  6         1
  7         2
  8         5
  9         3
  10        2
  11        4
  12        1
}\loadedtable
\pgfplotstabletypeset[
  row predicate/.code={%
    \pgfplotstablegetelem{#1}{obs}\of{\loadedtable}
    \ifnum\pgfplotsretval=??\relax %Use some seq operator?
      \else\pgfplotstableuserowfalse
    \fi}
]{\loadedtable}
\end{document}

1 Answers1

8

You can use the regular Mod operation for this.

\documentclass{standalone}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstableread{
 obs      number
  1         2
  2         5
  3         3
  4         2
  5         4
  6         1
  7         2
  8         5
  9         3
  10        2
  11        4
  12        1
}\loadedtable
\pgfplotstabletypeset[
  row predicate/.code={%
    \pgfplotstablegetelem{#1}{obs}\of{\loadedtable}
    \pgfmathparse{int(Mod(\pgfplotsretval,4)}
    \ifnum\pgfmathresult=0\relax
      \else\pgfplotstableuserowfalse
    \fi}
]{\loadedtable}
\end{document}

enter image description here

percusse
  • 157,807