Friday, 23 August 2013

Sorting a table according to values in another table

Sorting a table according to values in another table

I have two tables (A and B), both with a string valued column and an
integer valued column. What i would like to actually have is a sorted
table B sorted by the values of table A. The crucial point is that the
rows are identified by the string value, not the index, and that B does
not contain all rows that A has (otherwise i could just sort according to
the string column first).
\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\def\histocomp#1 sort on #2{
\pgfplotstableread{#2}\sortOnTable
\begin{tikzpicture}
\begin{axis}
\pgfplotstablesort[sort key=index,sort key
from=\sortOnTable]\loadedtable\sortOnTable
\addplot+ [no markers] table[x expr=\coordindex, y index=1] \loadedtable;
\pgfplotstableread{#1}\loadedtable
\pgfplotstablesort[sort key=index,sort key
from=\sortOnTable]\loadedtable\loadedtable
\addplot+ [only marks] table[x expr=\coordindex, y index=1] \loadedtable;
\end{axis}
\end{tikzpicture}
}
\begin{document}
\histocomp{B} sort on {A}
\end{document}
A:
index values
foo 0.5
bar 0.2
baz 0.7
B:
index values
bar 0.8
baz 0.5
Is there such a thing as an outer join or something?

No comments:

Post a Comment