我正在使用 R-exams 并且我想生成一個復式表,但是每次都有一組不同的值(我提出了 5 個不同的值:data1、data2、data3、data4、data5),但它不起作用,也沒有帶計數器,也不帶“樣品”。
我怎么能做到?謝謝
datos1 = c(0 , 2 , 4 , 2, 4 , 8, 13, 6, 12)
datos2 = c(11 , 2 , 4 , 2, 4 , 8, 3, 6, 12)
datos3 = c(12 , 2 , 14 , 2, 4 , 28, 3, 6, 12)
datos4 = c(13 , 2 , 4 , 2, 4 , 8, 3, 6, 12)
datos5 = c(1 , 2 , 4 , 22, 4 , 8, 3, 6, 12)
w9 <- sample(c(datos1, datos2, datos3, datos4, datos5),1)
tabla = cbind (expand.grid (list (Y = c ("3","5","6") ,
X = c ("6","8","9"))), count = w9)
ftable (xtabs(count ~ Y X, tabla ))
uj5u.com熱心網友回復:
謝謝你的澄清,阿米莉亞:)
c(datos1, datos2, datos3, datos4, datos5)將它們組合成一個長向量,然后樣本只是從這些中獲取 1 個值。相反,您想將它們放在一個串列中,然后進行采樣。這使它們分開,因此樣本然后查看串列級別并隨機抽取一個。見下文:
w9 <- sample(list(datos1, datos2, datos3, datos4, datos5), 1)
# to extract it from the list back in to the same format as datos1, datos2 etc.
w9 <- unlist(w9)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/388798.html
標籤:r
