我正在研究 Kruschke 中的示例Doing Bayesian Data Analysis
,需要一些帮助来了解如何将数据转换为他的代码示例所需的格式。在第 22 章中,他有一张这样的桌子
Blue Brown Green Hazel
Black 20 68 5 15
Blond 94 7 16 10
Brunette 84 119 29 54
Red 17 26 14 14
我很乐意通过将表格输入电子表格并像这样R
使用read.table("clipboard", header=T, sep="\t")
或输入表格来输入表格R
con.table2 <- matrix(c(20,68,5,15,94,7,16,10,84,119,29,54,17,26,14,14),nrow=4,byrow=TRUE)
dimnames(con.table2) <- list(c("Black","Blond","Brunette","Red"),c("Blue","Brown","Green","Hazel"))
但是在他的代码中,他像这样展示了这个表格,准备好进行分析(完整的代码在这里http://www.indiana.edu/~kruschke/DoingBayesianDataAnalysis/Programs/PoissonExponentialJagsSTZ.R)
Freq = c(68,119,26,7,20,84,17,94,15,54,14,10,5,29,14,16)
Eye = c("Brown","Brown","Brown","Brown","Blue","Blue","Blue","Blue","Hazel" # runs off the page of his book
Hair = c("Black","Brunette","Red","Blond","Black","Brunette","Red","Blond","Black" # runs off the page of his book
看起来该表已转换为三个向量。最有效的方法是什么?我想用我自己的数据替换他的数据,所以学习如何将数据转换为分析所需的格式会很棒。