gpt4 book ai didi

r - 如何获取列中唯一值的表计数

转载 作者:行者123 更新时间:2023-12-04 16:33:29 24 4
gpt4 key购买 nike

我有这个矩阵 mymat .我知道我可以做 table((mymat[,"col1"])获取 col1 中每个项目的数量.但是,如果 col2 中有唯一值,我只想要计数。对于 mymat下面,我想要这个结果:

app  gg  chh
1 2 1

麦特
col1   col2
app d
app d
gg e
gg f
gg e
chh f
chh f
chh f

最佳答案

您可以使用 unique对数据进行子集化(适用于 matrixdata.frame ),然后调用 table :
table(unique(mymat)[,1])
这返回

# app chh  gg 
# 1 1 2

关于r - 如何获取列中唯一值的表计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36015144/

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