私のデータの合否ステータスを以下に要約したいと思います。言い換えれば、各製品/タイプの合格と不合格のケースの数を伝えたいと思います。Rプログラミング:plyr ddplyで列の値をカウントする方法
product type N
1 p1 t1 6
2 p1 t2 6
3 p2 t1 6
4 p2 t2 6
望ましい結果は次のようになります。
library(ggplot2)
library(plyr)
product=c("p1","p1","p1","p1","p1","p1","p1","p1","p1","p1","p1","p1","p2","p2","p2","p2","p2","p2","p2","p2","p2","p2","p2","p2")
type=c("t1","t1","t1","t1","t1","t1","t2","t2","t2","t2","t2","t2","t1","t1","t1","t1","t1","t1","t2","t2","t2","t2","t2","t2")
skew=c("s1","s1","s1","s2","s2","s2","s1","s1","s1","s2","s2","s2","s1","s1","s1","s2","s2","s2","s1","s1","s1","s2","s2","s2")
color=c("c1","c2","c3","c1","c2","c3","c1","c2","c3","c1","c2","c3","c1","c2","c3","c1","c2","c3","c1","c2","c3","c1","c2","c3")
result=c("pass","pass","fail","pass","pass","pass","fail","pass","fail","pass","fail","pass","fail","pass","fail","pass","pass","pass","pass","fail","fail","pass","pass","fail")
df = data.frame(product, type, skew, color, result)
次cmdはパス+の総数は例を失敗したが、私はパスのために個別の列をしたいと
dfSummary <- ddply(df, c("product", "type"), summarise, N=length(result))
結果は失敗を返します
product type Pass Fail
1 p1 t1 5 1
2 p1 t2 3 3
3 p2 t1 4 2
4 p2 t2 3 3
私が試みた気にいらないよう:
dfSummary <- ddply(df, c("product", "type"), summarise, Pass=length(df$product[df$result=="pass"]), Fail=length(df$product[df$result=="fail"]))
が、結果は失敗し、合格のための壮大なtotatlているので、明らかにそれは間違っているのです。
お気軽にご連絡ください! よろしく、 Riad。
完璧な、それは私が必要なものです!迅速な答えのためのThx! – Riad