# How to plot every 4th row using pgfplotstable?

This seems very related to How to display every 4th row in a large data file using pgfplotstable?. I just try to plot the filtered rows but am missing something here. Here is the MWE (I copied the example from previous link).

\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

\pgfplotstabletypeset[
row predicate/.code={%
\pgfmathparse{int(Mod(\pgfplotsretval,4)}
\ifnum \pgfmathresult = 0
\else \pgfplotstableuserowfalse
\fi}

\begin{tikzpicture}
\begin{axis}
\pgfmathparse{int(Mod(\pgfplotsretval, 4))}
\ifnum \pgfmathresult = 0
\else
\def \pgfmathresult{}
\fi},
\end{axis}
\end{tikzpicture}


The tabletypeset works fine but the plot does not work. Is there an easy fix?

On a side note, is there anyway to save the filtered table as a new macro so that I can use it in a plot directly?

Any help is appreciated.

For plotting only each n-th coordinate, PGFPlots already provides the mechanism mark repeat=<integer> and mark offset=<integer>:

\documentclass[border=5mm]{standalone}

\usepackage{pgfplots, pgfplotstable}
\begin{document}

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

\pgfplotstabletypeset[
row predicate/.code={%
\pgfmathparse{int(Mod(\pgfplotsretval,4)}%
\ifnum \pgfmathresult = 0 %
\else \pgfplotstableuserowfalse%
\fi}

• Thanks! This is really neat. Any suggestions to my side note? Can we save the filtered table as a new macro in pgfplotstable? – Zhen Sun Aug 5 '14 at 18:37