ax ay az bx by bz cx cy cz dx dy dz ex ey ez Hid PX PY PZ
1 330 295 998 0 0 0 0 0 0 0 0 0 0 0 0 0 279.6626 310.3374 923.4111
2 0 0 0 260 375 941 0 0 0 0 0 0 0 0 0 0 279.6626 310.3374 923.4111
3 0 0 0 245 375 949 0 0 0 0 0 0 0 0 0 0 279.6667 310.2424 924.7394
4 330 295 998 0 0 0 0 0 0 0 0 0 0 0 0 0 279.6667 310.2424 924.7394
对于相同的PX,PY和PZ值,我想合并行 例如,输出应该是
ax ay az bx by bz cx cy cz dx dy dz ex ey ez Hid PX PY PZ
1 330 295 998 260 375 941 0 0 0 0 0 0 0 0 0 0 279.6626 310.3374 923.4111
2 330 295 998 245 375 949 0 0 0 0 0 0 0 0 0 0 279.6667 310.2424 924.7394
答案 0 :(得分:3)
使用data.table
,您可以尝试此操作(您的data.frame称为df
):
library(data.table)
setDT(df)[, lapply(.SD, max), by=.(PX, PY, PZ)]
# PX PY PZ ax ay az bx by bz cx cy cz dx dy dz ex ey ez Hid
#1: 279.6626 310.3374 923.4111 330 295 998 260 375 941 0 0 0 0 0 0 0 0 0 0
#2: 279.6667 310.2424 924.7394 330 295 998 245 375 949 0 0 0 0 0 0 0 0 0 0