[英]R: How to add a column to a dataframe with in each row the cumulative sum of all its previous rows?
[英]Add row to sum each column in dataset in R
我有一個表格,其中有 8 個定義的扇區作為行,時間段作為列。
2001 Q1 2001 Q2 2001 Q3
Agriculture 500 400 300
Manufacturing 100 150 100
Finance 1000 1500 1000
TOTAL?
我正在嘗試對每一列求和,但似乎數據是“具有 8 個級別的因子”。 8 是我擁有的扇區數量。 請幫助總結每列和/或將數據格式更改為數字的最佳解決方案?
我們可以使用addmargins
addmargins(as.matrix(df1), 1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.