用 base R 也行:
df_temp=t(apply(mtcars, 1, cumsum) )
df_temp
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 27.0 187.0 297.0 300.90 303.520 319.980 319.980 320.980 324.980 328.980
Mazda RX4 Wag 21.0 27.0 187.0 297.0 300.90 303.775 320.795 320.795 321.795 325.795 329.795
Datsun 710 22.8 26.8 134.8 227.8 231.65 233.970 252.580 253.580 254.580 258.580 259.580
Hornet 4 Drive 21.4 27.4 285.4 395.4 398.48 401.695 421.135 422.135 422.135 425.135 426.135
Hornet Sportabout 18.7 26.7 386.7 561.7 564.85 568.290 585.310 585.310 585.310 588.310 590.310
Valiant 18.1 24.1 249.1 354.1 356.86 360.320 380.540 381.540 381.540 384.540 385.540
Duster 360 14.3 22.3 382.3 627.3 630.51 634.080 649.920 649.920 649.920 652.920 656.920
Merc 240D 24.4 28.4 175.1 237.1 240.79 243.980 263.980 264.980 264.980 268.980 270.980
Merc 230 22.8 26.8 167.6 262.6 266.52 269.670 292.570 293.570 293.570 297.570 299.570
Merc 280 19.2 25.2 192.8 315.8 319.72 323.160 341.460 342.460 342.460 346.460 350.460
Merc 280C 17.8 23.8 191.4 314.4 318.32 321.760 340.660 341.660 341.660 345.660 349.660
Merc 450SE 16.4 24.4 300.2 480.2 483.27 487.340 504.740 504.740 504.740 507.740 510.740
Merc 450SL 17.3 25.3 301.1 481.1 484.17 487.900 505.500 505.500 505.500 508.500 511.500
Merc 450SLC 15.2 23.2 299.0 479.0 482.07 485.850 503.850 503.850 503.850 506.850 509.850
Cadillac Fleetwood 10.4 18.4 490.4 695.4 698.33 703.580 721.560 721.560 721.560 724.560 728.560
Lincoln Continental 10.4 18.4 478.4 693.4 696.40 701.824 719.644 719.644 719.644 722.644 726.644
Chrysler Imperial 14.7 22.7 462.7 692.7 695.93 701.275 718.695 718.695 718.695 721.695 725.695
Fiat 128 32.4 36.4 115.1 181.1 185.18 187.380 206.850 207.850 208.850 212.850 213.850
Honda Civic 30.4 34.4 110.1 162.1 167.03 168.645 187.165 188.165 189.165 193.165 195.165
Toyota Corolla 33.9 37.9 109.0 174.0 178.22 180.055 199.955 200.955 201.955 205.955 206.955
Toyota Corona 21.5 25.5 145.6 242.6 246.30 248.765 268.775 269.775 269.775 272.775 273.775
Dodge Challenger 15.5 23.5 341.5 491.5 494.26 497.780 514.650 514.650 514.650 517.650 519.650
AMC Javelin 15.2 23.2 327.2 477.2 480.35 483.785 501.085 501.085 501.085 504.085 506.085
Camaro Z28 13.3 21.3 371.3 616.3 620.03 623.870 639.280 639.280 639.280 642.280 646.280
Pontiac Firebird 19.2 27.2 427.2 602.2 605.28 609.125 626.175 626.175 626.175 629.175 631.175
Fiat X1-9 27.3 31.3 110.3 176.3 180.38 182.315 201.215 202.215 203.215 207.215 208.215
Porsche 914-2 26.0 30.0 150.3 241.3 245.73 247.870 264.570 264.570 265.570 270.570 272.570
Lotus Europa 30.4 34.4 129.5 242.5 246.27 247.783 264.683 265.683 266.683 271.683 273.683
Ford Pantera L 15.8 23.8 374.8 638.8 643.02 646.190 660.690 660.690 661.690 666.690 670.690
Ferrari Dino 19.7 25.7 170.7 345.7 349.32 352.090 367.590 367.590 368.590 373.590 379.590
Maserati Bora 15.0 23.0 324.0 659.0 662.54 666.110 680.710 680.710 681.710 686.710 694.710
Volvo 142E 21.4 25.4 146.4 255.4 259.51 262.290 280.890 281.890 282.890 286.890 288.890