Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filtering a grouped table removes indices attribute #880

Closed
Mullefa opened this issue Jan 11, 2015 · 1 comment
Closed

filtering a grouped table removes indices attribute #880

Mullefa opened this issue Jan 11, 2015 · 1 comment
Assignees
Labels
Milestone

Comments

@Mullefa
Copy link

@Mullefa Mullefa commented Jan 11, 2015

For example:

# OK
iris %>% 
  group_by(Species) %>%
  attr("indices")

# not OK
iris %>% 
  group_by(Species) %>%
  filter(n() > 0) %>%
  attr("indices")

devtools::session_info()
# dplyr        0.4.0.9000 2015-01-11 Github (hadley/dplyr@cd91f33)    

If this is intended (I imagine its not), then at least the n_groups() method for a grouped_df needs to be fixed.

@hadley hadley added this to the 0.5 milestone May 19, 2015
@romainfrancois romainfrancois self-assigned this Aug 23, 2015
@romainfrancois
Copy link
Member

@romainfrancois romainfrancois commented Aug 23, 2015

Seems to no longer be the case:

# not OK
> iris %>%
+   group_by(Species) %>%
+   filter(n() > 0) %>%
+   attr("indices")
[[1]]
 [1]  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
[26] 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

[[2]]
 [1] 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
[26] 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

[[3]]
 [1] 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
[20] 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
[39] 138 139 140 141 142 143 144 145 146 147 148 149

However, there seems to be a problem, indices are not updated at all :

> res <- iris %>% group_by(Species) %>% filter( Sepal.Length > 5 )
> res
Source: local data frame [118 x 5]
Groups: Species

   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1           5.1         3.5          1.4         0.2  setosa
2           5.4         3.9          1.7         0.4  setosa
3           5.4         3.7          1.5         0.2  setosa
4           5.8         4.0          1.2         0.2  setosa
5           5.7         4.4          1.5         0.4  setosa
6           5.4         3.9          1.3         0.4  setosa
7           5.1         3.5          1.4         0.3  setosa
8           5.7         3.8          1.7         0.3  setosa
9           5.1         3.8          1.5         0.3  setosa
10          5.4         3.4          1.7         0.2  setosa
..          ...         ...          ...         ...     ...
> res %>% attr("indices")
[[1]]
 [1]  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
[26] 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

[[2]]
 [1] 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
[26] 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

[[3]]
 [1] 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
[20] 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
[39] 138 139 140 141 142 143 144 145 146 147 148 149


romainfrancois added a commit that referenced this issue Aug 25, 2015
better handling of attributes on grouped filter. closes #880
krlmlr pushed a commit to krlmlr/dplyr that referenced this issue Mar 2, 2016
better handling of attributes on grouped filter. closes tidyverse#880
@lock lock bot locked as resolved and limited conversation to collaborators Jun 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants