Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用重复测量的数据库,我需要按类别计算数字向量的总和并删除重复项。
Category Area A 30A 15A 20B 45B 30C 12D 18D 22
Category Area
A 30
A 15
A 20
B 45
B 30
C 12
D 18
D 22
并转换为:
Category Area A 65B 75C 12D 40
A 65
B 75
D 40
我怎样才能在 R 中得到这个?
假设您有一个名为 df 的 data.frame,其中包含 Category 和 Area 列
df2 <- aggregate.data.frame(x = df["Area"], by = df["Category"], FUN = sum)