Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question

1 Answer 1

up vote 8 down vote accepted

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

share|improve this answer
    
Oops, make it \pgfmathresult=1. –  percusse Nov 2 '12 at 17:06
    
Awe, beautiful, works like a charm. Thanks! –  Luke Nov 2 '12 at 17:16
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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