[英]Counts table in R
I have the following table: 我有下表:
Type B1 B2 B3 B4 B5
1 Simple_repeat 0 0 0 0 0
2 Simple_repeat 0 1 0 0 1
3 Simple_repeat 10 1 9 1 35
4 Simple_repeat 3 5 2 7 10
5 Simple_repeat 8 1 1 9 13
6 Satellite 0 0 0 0 0
And I want to make a table of uniqe Types
. 我想制作一个uniqe Types
表。
So, my desired output : 所以,我想要的输出 :
Type B1 B2 B3 B4 B5
1 Simple_repeat 21 8 12 17 59
2 Satellite 0 0 0 0 0
I tried using table
without success. 我尝试使用table
没有成功。 What should I do? 我该怎么办?
You could try 你可以试试
library(dplyr)
df %>%
group_by(Type) %>%
summarise_each(funs(sum))
Or 要么
aggregate(.~Type, df, sum)
Or 要么
library(data.table)
setDT(df)[, lapply(.SD, sum), Type]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.