[R] Something simple not working in group_by

Sariya, Sanjeev @@5505 @end|ng |rom cumc@co|umb|@@edu
Mon Jul 9 23:39:44 CEST 2018


Strange. Worked fine on:

R version 3.4.2 (2017-09-28)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)

Commands:

m <- data.frame( id = rep(1:3, each=2), score = rep(c(6,3), each=3) )

as.data.frame(m %>% group_by(id) %>% mutate(total = cumsum(score)))

  id score total
1  1     6     6
2  1     6    12
3  2     6     6
4  2     3     9
5  3     3     3
6  3     3     6

-----Original Message-----
From: R-help <r-help-bounces using r-project.org> On Behalf Of Sumitrajit Dhar
Sent: Monday, July 9, 2018 5:35 PM
To: r-help using r-project.org
Subject: [R] Something simple not working in group_by

Hi Folks,

I am trying to get a group_by cumsum using:

R version 3.5.0 (2018-04-23) -- "Joy in Playing"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)

Here is an example of a simple construct that is not working.

m <- data.frame( id = rep(1:3, each=2), score = rep(c(6,3), each=3) )

m %>% group_by(id) %>% mutate(total = cumsum(score))

My output:

# A tibble: 6 x 3
# Groups:   id [3]
     id score total
  <int> <dbl> <dbl>
1     1     6     6
2     1     6    12
3     2     6    18
4     2     3    21
5     3     3    24
6     3     3    27

What am I missing? Thanks in advance.

Regards,
Sumit




More information about the R-help mailing list