我的数据框df如下所示:
Expenditure Group Rank
1 18.8 Nontrauma 1.0
2 20.0 Nontrauma 2.0
3 20.1 Nontrauma 3.0
4 20.9 Nontrauma 4.5
5 20.9 Nontrauma 4.5
6 21.4 Nontrauma 6.0
7 22.0 Trauma 7.0
8 22.7 Nontrauma 8.0
9 22.9 Nontrauma 9.0
10 23.0 Trauma 10.0
11 24.5 Trauma 11.0
12 25.8 Trauma 12.0
13 30.0 Trauma 13.0
14 37.6 Trauma 14.0
15 38.5 Trauma 15.0
我想提取创伤组的等级总和如下:
T = tapply(df$Rank, df$Group, sum)["Trauma"]
但是,变量T保留“创伤”标签,并将该标签传递给涉及它的所有计算。有没有办法摆脱标签,以便我保持一个简单的数值?
答案 0 :(得分:1)
尝试:
> sum(ddf[ddf$Group=='Trauma',]$Rank)
[1] 82