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.

I have a table, read from a file, and I would like to display only rows which have a specific value in a given column.

Here is an ECM:

\documentclass{minimal}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstableread{
  num       value
  1         2
  2         5
  1         3
  3         2
  1         4
  2         1
}\data
\pgfplotstabletypeset[row predicate/.code={%
  \ifnum\pgfplotstablegetelem{#1}{num}\of{\data}=1\relax
  \else\pgfplotstableuserowfalse\fi}]{\data}
\end{document}

I would expect to seen only rows whose num value is 1. But I get an error when compiling:

ERROR: Missing number, treated as zero.

--- TeX said ---
 
                   \begingroup 
l.14 ...after\pgfplotstableuserowfalse\fi}]{\data}

Do you have any idea on what to do so that only specific rows are displayed?

share|improve this question
add comment

1 Answer

up vote 10 down vote accepted

You're almost there! However, the macro \pgfplotstablegetelem doesn't "evaluate" to the value you're after, but rather stores it in a macro called \pgfplotsretval. So your code works if you write it like

\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstableread{
  num       value
  1         2
  2         5
  1         3
  3         2
  1         4
  2         1
}\data
\pgfplotstabletypeset[row predicate/.code={%
  \pgfplotstablegetelem{#1}{num}\of{\data}
  \ifnum\pgfplotsretval=1\relax
  \else\pgfplotstableuserowfalse\fi}]{\data}
\end{document}

share|improve this answer
    
Gosh I had the pgfplotstable manual opened on the page talking about pgfplotstablegetelem, and I don't know how I managed not to see it! Thanks a lot for your help! –  kelux Feb 8 '12 at 14:48
add comment

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.