ある列のセルの内容を別の列に基づいて後処理する

ある列のセルの内容を別の列に基づいて後処理する

私はこの投稿と非常によく似たことをやろうとしています:

pgfplotstable: 列ごとにセルの内容を条件付きで後処理する

ただし、別の列の内容に基づいて列を後処理したいと思います。たとえば、対応するが 2 より大きい場合は、列*に を追加したいと思います。coefficientt-value

表では、通常、 と のみを報告しcoefficientstandard errorは報告しません。の値に基づいて列t-valueを後処理したいと思います。coefficientcoefficient/standard error

以下は MWE です。

\documentclass{article}
\usepackage{pgfplotstable}
\begin{filecontents*}{test1.dat}
coefficient {standard error} 
-.0159375    .008852
-.0107286   .0091658
.0042201   .0089453
.0108719   .0038041
\end{filecontents*}

\begin{document}
\pgfplotstableread{test1.dat}\results
\pgfplotstablecreatecol[expr={\thisrow{coefficient}/\thisrow{standard error}}]{t-value}{\results}

\def\bordervalue{2}
\pgfplotstabletypeset[
columns={coefficient, standard error, t-value},
columns/t-value/.style={ 
    %preproc/expr = {100*##1},
    postproc cell content/.style={
    /pgfplots/table/@cell content/.add={}{%
    \pgfmathparse{int(greater(##1,\bordervalue))}
    \ifnum\pgfmathresult=1
       $^*$
    \fi
    },
    },
},
]\results
\end{document}

ここに画像の説明を入力してください

を報告する必要がないように、 を 列*に配置するにはどうすればよいですか?coefficientt-value

どのような助けでも大歓迎です。

答え1

ちょっとトリッキーな方法でもできます:

columns/coefficient/.style={
postproc cell content/.append code={%
\pgfplotstablegetelem{\pgfplotstablerow}{t-value}\of{\results}%
\pgfmathsetmacro{\TvalueTest}{\pgfplotsretval > \bordervalue ? 1 : 0}%
\ifthenelse{\TvalueTest = 1}% if 
{\pgfkeysalso{/pgfplots/table/@cell content/.add={$}{*{}^*$}} }% then
{}% else
}},

ところで、列に星を追加する方法を簡略化しましたt-value:
\pgfmathparse{##1 > \bordervalue ? "^*" : ""}\pgfmathresult

ここに画像の説明を入力してください

\documentclass[margin=5pt]{standalone}
%\documentclass{article}

\usepackage{pgfplotstable}
\usepackage{ifthen}
\usepackage{colortbl}

\usepackage{filecontents}
\begin{filecontents*}{test1.dat}
coefficient {standard error} 
-.0159375    .008852
-.0107286   .0091658
.0042201   .0089453
.0108719   .0038041
\end{filecontents*}

\begin{document}
\pgfmathsetmacro\bordervalue{2}

\pgfplotstableread[]{test1.dat}\results
\pgfplotstablecreatecol[expr={\thisrow{coefficient}/\thisrow{standard error}}]{t-value}{\results}

\pgfplotstabletypeset[
columns={coefficient, standard error, t-value},
columns/t-value/.style={numeric type,  
postproc cell content/.style={
/pgfplots/table/@cell content/.add={$}{
\pgfmathparse{##1 > \bordervalue ? "^*" : ""}\pgfmathresult$  % New
},},
},
% New:
columns/coefficient/.style={
postproc cell content/.append code={%
\pgfplotstablegetelem{\pgfplotstablerow}{t-value}\of{\results}%
\pgfmathsetmacro{\TvalueTest}{\pgfplotsretval > \bordervalue ? 1 : 0}%
\ifthenelse{\TvalueTest = 1}% if 
{\pgfkeysalso{/pgfplots/table/@cell content/.add={\cellcolor{pink}$}{*{}^*$}}}% then
{}% else
}},
]\results
\end{document}

関連情報