【发布时间】:2018-03-14 07:04:26
【问题描述】:
我一直在用 R 语言为这个具有大数据集的特定任务开发代码
示例数据框如下所示:
mon abb Apr May Jun Jul Aug Sep Oct Nov
5 May 2 4 2 5 0 0 7 0
5 May 6 5 1 1 3 0 6 4
5 May 3 1 0 1 1 2 8 8
7 Jul 5 4 1 0 0 0 9 1
7 Jul 3 3 4 3 4 4 9 9
7 Jul 4 2 3 3 1 2 7 4
7 Jul 4 1 4 2 3 5 4 3
6 Jun 4 0 4 3 3 6 5 5
7 Jul 4 4 5 3 4 8 8 8
5 May 4 -1 6 4 4 9 5 4
7 Jul 4 -2 4 4 2 6 6 9
对于与列名月份匹配的列 abb 中月份中的每一行,相应单元格中的数字将与后续数字进行比较,并且列 count 的创建次数小于另一个列中的数字细胞。希望清楚
Output would look like
mon abb Apr May Jun Jul Aug Sep Oct Nov Count
5 May 2 4 2 5 0 0 7 0 2
5 May 6 5 1 1 3 0 6 4 1
5 May 3 1 0 1 1 2 8 8 3
7 Jul 5 4 1 0 0 0 9 1 2
7 Jul 3 3 4 3 4 4 9 9 4
7 Jul 4 2 3 3 1 2 7 4 2
7 Jul 4 1 4 2 3 5 4 3 4
6 Jun 4 0 4 3 3 6 5 5 3
7 Jul 4 4 5 3 4 8 8 8 4
5 May 4 -1 6 4 4 9 5 4 6
7 Jul 4 -2 4 4 2 6 6 9 3
我创建了列索引
conshead$b=(match(conshead[,conshead$monthabb],colnames(conshead[,24:31]))+23)
无法继续进行。请分享一个更好的逻辑。
【问题讨论】:
标签: r dataframe multiple-columns