私の目標は次のとおりです。二分応答(たとえば、0と1)のデータフレームが与えられた場合、次のような要約行列を作成するにはどうすればよいですか。1)2つの列(最初の質問に正しく答えるためのものと、間違って答えるためのもの)、 2)特定の合計スコアを取得する個人の数に関する行があります。
たとえば、50人の回答者と5つの質問があるとします。これは、6つの応答パターンがあることを意味します(すべて正しくない/ 0、次に1、2、3、および4つ正しい、最後にすべて正しい/ 1)。結果の行列オブジェクトを次のようにしたいと思います。
... INCORRECT ..... CORRECT <-- pertaining to a 0 or 1 on the first item respectively
[1]... 10 ............ 0 <-- indicating people who, after responded 0 on the first question, responded 0 on all questions (5 zeroes)
[2]... 8 ............ 2 <-- indicating 12 people who got 1 correct (8 got the first question incorrect, 2 got the first question correct)
[3]... 4 ............. 8 <-- indicating 12 people who got 2 correct (4 got the first question incorrect but got 2 of the other questions correct, 8 got the first question and 1 other correct)
[4]... 6 ............. 3 <-- indicating 9 people who got 3 correct
[5]... 3 ............. 4 <-- indicating 7 people who got 4 correct
[6]... 0 ............. 8 <-- pertaining to the 8 people who answered all 5 questions correctly (necessarily indicating they got the first question correct).
私の考えでは、最初の質問のパフォーマンスでデータフレームを分割し(一度に1列ずつ作業)、各行(参加者)の合計スコアを見つけて、それらを最初の列に集計する必要があります。次に、2番目にも同じことをしますか?
これはパッケージに組み込まれる予定なので、基本関数のみを使用してこれを行う方法を理解しようとしています。
これは、私が使用するものと同様のデータセットの例です。
n <- 50
z <- c(0, 1)
samp.fun <- function(x, n){
sample(x, n, replace = TRUE)
}
data <- data.frame(0)
for (i in 1:5){
data[1:n, i] <- samp.fun(z, n)
}
names(data)[1:5] <- c("x1", "x2", "x3", "x4", "x5")
どんな考えでも大歓迎です!