這是發病率數據。按農場和年份合併的死亡和風險時間合併 我試圖使用方法= 「cohort.time」(epiR軟件包)將數據轉換爲epi.2by2所需的格式。R數據框到3維的表格
示例數據:
test <- rbind(c(12, 2,0), c(29,16,26), c(6941, 6083, 5051), c(4555, 5148, 3608))
colnames(test) <- c(3, 3.5, 4)
rownames(test) <- c("deaths-unexposed", "deaths-exposed", "timeatrisk-unexposed", "timeatrisk-exposed")
farm-year 3 3.5 4
deaths-unexposed 12 2 0
deaths-exposed 29 16 26
timeatrisk-unexposed 6941 6083 5051
timeatrisk-exposed 4555 5148 3608
需要輸出:
, , farm_year = 3
deaths timeatrisk
exposed
1 29 6941
0 12 4555
, , farm_year = 3.5
deaths timeatrisk
exposed
1 16 6083
0 2 6148
等
我試着用表()在幾個方面,但它給了我很多的0的延長表每個farm_year階層。我相信這是一個簡單的答案(重塑?xtabs?)我找不到它!
這確實是 - 我會tidyverse添加到我的包劇目! – CaitlinP