Box*_*uan 3 r sum data-manipulation
我有一个这样的数据框:
A B Ind
1 10 8 1
2 9 10 2
3 7 1 2
4 19 20 1
5 . . .
Run Code Online (Sandbox Code Playgroud)
如何根据Ind值对列进行求和?如果Ind==1,则从列总和A,if Ind==2,列总和B.例如,前4行的输出应为10+10+1+19=30,其中前10行为A,第二行为10 B,第三行为1 B,第四行为19 A.