# Reordering the rows of a table using pgfplotstable

I have a table in a file called dummy.txt which contains the following data:

value1  value2  value3
1   11  2.13652246624232
2   12  0.513442717554625
3   13  1.69712766271722
4   14  -1.57360405275275
5   15  0.784061900065905


I can print the table via

\pgfplotstabletypeset[
col sep=tab,
columns={value2,value1}
]{dummy.txt}


Is there a similarly easy way to select the order and the actual selection for the rows, as there is for the columns?

I had a look at the manual, and the only thing which came close was the row predicate argument, which seemed a bit too powerful for my goal of selecting row number 2,3 and 5. And I don't know how to work with logical predicates in TeX.

• What is the order you want to achieve? Jul 7 '14 at 1:06
• @percusse: As this is just an example table, I guess that 5, 2, 3 would serve as a good example for my needs. Jul 7 '14 at 1:40

"Reordering" sounds a lot like sorting. In fact, you can sort the table according to your desired order - you only need a further (temporary) column with the order values. Of course, sorting does not filter. But you can easily use skip rows between index to filter the sorted result since the unwanted entries can easily be sorted to the end:

\documentclass{standalone}

\usepackage{pgfplotstable}

\begin{document}
\pgfplotstabletypeset[
columns={value2,value1},
sort,sort key=sort order,
create on use/sort order/.style={
create col/set list={100,1,2,100,0},
},
skip rows between index={3}{100},
]{
value1  value2  value3
1   11  2.13652246624232
2   12  0.513442717554625
3   13  1.69712766271722
4   14  -1.57360405275275
5   15  0.784061900065905
}
\end{document}


this code sorts according to the values in column sort order. This column does not exist, it will be created according to the create on use/sort order specification -- and that contains an explicit list of 5 values, one for each row. The row with value1=5 receives 0, the row with value1=2 receives 1, and the row with value1=3 receives 2 - all other ones get an 100. You can easily add columns={value2,value1,sort order} to see the results.

You mention that this is "just an example table". If you have a huge table, this create on use stuff can easily become tedious. In this case, you should probably add a "real" column sort order to your tables.