gpt4 book ai didi

r - 相对频率表怎么画

转载 作者:行者123 更新时间:2023-12-02 05:33:42 24 4
gpt4 key购买 nike

Src=as.factor(c("nc","us","us","nc","nc","ci","nn","pr","nc","nc","ak","ak","ak","ak","ci","hv","ak","ci","nc","nc"))
Version = as.factor(c(0,4,7,0,0,0,9,0,0,0,1,1,1,1,0,2,1,0,0,0))
table(Src,Version)

输出:

    Version
Src 0 1 2 4 7 9
ak 0 5 0 0 0 0
ci 3 0 0 0 0 0
hv 0 0 1 0 0 0
nc 7 0 0 0 0 0
nn 0 0 0 0 0 1
pr 1 0 0 0 0 0
us 0 0 0 1 1 0

我可以不显示计数,而是显示相对频率吗?

最佳答案

当然。你可以使用 prop.table() 达到这个效果:

prop.table(table(Src, Version))

这将生成如下表格:

    Version
Src 0 1 2 4 7 9
ak 0.00 0.25 0.00 0.00 0.00 0.00
ci 0.15 0.00 0.00 0.00 0.00 0.00
hv 0.00 0.00 0.05 0.00 0.00 0.00
nc 0.35 0.00 0.00 0.00 0.00 0.00
nn 0.00 0.00 0.00 0.00 0.00 0.05
pr 0.05 0.00 0.00 0.00 0.00 0.00
us 0.00 0.00 0.00 0.05 0.05 0.00

您可以使用可选参数 margin 来请求行或列的相对频率。

关于r - 相对频率表怎么画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14581204/

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