gpt4 book ai didi

r - 表中的边际总数

转载 作者:行者123 更新时间:2023-12-03 10:11:52 25 4
gpt4 key购买 nike

我有一个数据框,其中包含在不同日期从临床分离株中识别出的许多感染。

到目前为止,我已经将数据整理成我想开始使用的形状。我正在尝试为报告的描述性统计准备一系列表。

我一直在使用ftable并获得以下信息:

onset.types <- ftable(SAB$Onset,SAB$MRSA.Type,year(SAB$Collection.Date))
2005 2006 2007 2008 2009 2010

Community 454 472 512 499 525 512
AUS-2/3-like 28 23 27 29 32 38
EMRSA-15-like 9 4 4 9 8 8
nmMRSA 40 47 53 39 64 60
Other mMRSA 1 3 3 11 5 9
unclassified MRSA 0 2 0 0 1 1
Hospital 163 163 156 164 149 165
AUS-2/3-like 31 33 27 31 29 28
EMRSA-15-like 3 8 5 9 4 3
nmMRSA 10 9 13 17 13 12
Other mMRSA 5 1 6 2 3 10
unclassified MRSA 2 0 1 0 0 0

两个问题:

1:如何计算边际总计

2:是否有一种简单的方法来计算百分比以及重新计算边际总数

我尝试了Epitools,但没有找到我想要的有用的工具。

非常感谢。

最佳答案

要添加边距,请使用addmargins()

addmargins(table(state.division, state.region))
state.region
state.division Northeast South North Central West Sum
New England 6 0 0 0 6
Middle Atlantic 3 0 0 0 3
South Atlantic 0 8 0 0 8
East South Central 0 4 0 0 4
West South Central 0 4 0 0 4
East North Central 0 0 5 0 5
West North Central 0 0 7 0 7
Mountain 0 0 0 8 8
Pacific 0 0 0 5 5
Sum 9 16 12 13 50

要计算百分比,请使用 prop.table()
prop.table(table(state.division, state.region))
state.region
state.division Northeast South North Central West
New England 0.12 0.00 0.00 0.00
Middle Atlantic 0.06 0.00 0.00 0.00
South Atlantic 0.00 0.16 0.00 0.00
East South Central 0.00 0.08 0.00 0.00
West South Central 0.00 0.08 0.00 0.00
East North Central 0.00 0.00 0.10 0.00
West North Central 0.00 0.00 0.14 0.00
Mountain 0.00 0.00 0.00 0.16
Pacific 0.00 0.00 0.00 0.10

关于r - 表中的边际总数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6649004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com