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}
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

  • Oops, make it \pgfmathresult=1. – percusse Nov 2 '12 at 17:06
  • Note that the use of \pgfplotstablegetelem might be very inefficient, especially for "large tables" (unless "large" means <50 rows). But since obs is more-or-less equivalent to \pgfplotstablerow, you may want to prefer \pgfplotstablerow – Christian Feuersänger Nov 10 '12 at 21:36
  • @ChristianFeuersänger Indeed I remember your warning for that in the manual too, I was just replicating OP's code. – percusse Nov 10 '12 at 23:43
  • @Luke FYI; consider Christian's comment seriously :) – percusse Nov 10 '12 at 23:43
  • @percusse Hmm, makes sense. I was wondering why the compiling was taking longer than usual. I'll look into it. – Luke W. Johnston Nov 13 '12 at 1:30

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.