私のテーブルには、400 のクラスで分類された数千の行と、12 の列があります。
理想的な結果は、列「z」の最大値に基づいて、すべての元の列を含む 400 行 (各クラスに 1 行) のテーブルです。
これが私のデータの例です。R を使用して、この例で抽出された 2、4、7、8 行のみが必要です。
x y z cluster 1 712521.75 3637426.49 19.46 12 2 712520.69 3637426.47 19.66 12 * 3 712518.88 3637426.63 17.37 225 4 712518.4 3637426.48 19.42 225 * 5 712517.11 3637426.51 18.81 225 6 712515.7 3637426.58 17.8 17 7 712514.68 3637426.55 18.16 17 * 8 712513.58 3637426.55 18.23 50 * 9 712512.1 3637426.62 17.24 50 10 712513.93 3637426.88 18.08 50
私はこれらを含む多くの異なる組み合わせを試しました:
tapply(data$z, data$cluster, max) # returns only the max value and cluster columns which.max(data$z) # returns only the index of the max value in the entire table
plyr パッケージも読みましたが、解決策が見つかりませんでした。