按间隔数据帧汇总行 [英] Sum rows by interval Dataframe

查看:44
本文介绍了按间隔数据帧汇总行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要研究项目问题的帮助.

I need help in a research project problem.

代码问题是:我有一个名为 FRAMETRUE 的大数据框,需要在我将称为 Group1 的新列中逐行求和这些行的某些列.

The code problem is: i have a big data frame called FRAMETRUE, and a need to sum certain columns of those rows by row in a new column that I will call Group1.

例如:

head.table(FRAMETRUE)

Municipalities  1989  1990  1991  1992  1993  1994  1995  1996  1997
A                 3     3     5    2     3      4     2     5     3
B                 7     1     2    4     5      0     4     8     9
C                 10    15    1    3     2      NA    2     5     3
D                 7     0     NA   5     3       6    4     5     5
E                 5     1     2    4     0       3    5     4     2

我必须在名为 Group1 的新列中对从 1989 年到 1995 年的行中的值求和.像列 Group1 应该是

I must sum the values in the rows from 1989 to 1995 in a new column called Group1. like the column Group1 should be

Group1
  22
  23

等等...

我知道它一定很简单,我只是不明白,我还在学习 R

I know it must be something simple, I just don't get it, I'm still learning R

推荐答案

如果您正在寻找 R 解决方案,这里有一种方法:诀窍是使用 [ 结合行总和

If you are looking for an R solution, here's one way to do it: The trick is using [ combined with rowSums

FRAMETRUE$Group1 <- rowSums(FRAMETRUE[, 2:8], na.rm = TRUE)

这篇关于按间隔数据帧汇总行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆