-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Windowed rank functions don't work with character columns in tibbles #2988
Comments
Thanks, confirmed. Slightly less confusing reprex: # Packages already on the search path:
suppressPackageStartupMessages(library(dplyr))
# User code:
df_f <- data_frame(a = factor(c("a", "C", "z")))
df_s <- data_frame(a = c("a", "C", "z"))
print(df_f %>% mutate(r = dense_rank(a)))
#> # A tibble: 3 x 2
#> a r
#> <fctr> <int>
#> 1 a 1
#> 2 C 2
#> 3 z 3
print(df_s %>% mutate(r = dense_rank(a)))
#> Error in mutate_impl(.data, dots): STRING_ELT() can only be applied to a 'character vector', not a 'NULL' |
Please use |
We need to figure out how to sort character vectors quickly and consistently with base R first (#3044), before we can usefully look into this problem. |
Getting this now on @foo-bar-baz-qux code: library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
df <- data.frame(a = c("a", "C", "z"))
df_t <- data_frame(a = c("a", "C", "z"))
print(df %>% mutate(r = dense_rank(a)))
#> a r
#> 1 a 1
#> 2 C 2
#> 3 z 3
print(df_t %>% mutate(r = dense_rank(a)))
#> # A tibble: 3 x 2
#> a r
#> <chr> <int>
#> 1 a 2
#> 2 C 1
#> 3 z 3
print(df %>% mutate(r = min_rank(a)))
#> a r
#> 1 a 1
#> 2 C 2
#> 3 z 3
print(df_t %>% mutate(r = min_rank(a)))
#> # A tibble: 3 x 2
#> a r
#> <chr> <int>
#> 1 a 2
#> 2 C 1
#> 3 z 3
print(df %>% mutate(r = cume_dist(a)))
#> a r
#> 1 a 0.3333333
#> 2 C 0.6666667
#> 3 z 1.0000000
print(df_t %>% mutate(r = cume_dist(a)))
#> # A tibble: 3 x 2
#> a r
#> <chr> <dbl>
#> 1 a 0.667
#> 2 C 0.333
#> 3 z 1.00
print(df %>% mutate(r = percent_rank(a)))
#> a r
#> 1 a 0.0
#> 2 C 0.5
#> 3 z 1.0
print(df_t %>% mutate(r = percent_rank(a)))
#> # A tibble: 3 x 2
#> a r
#> <chr> <dbl>
#> 1 a 0.500
#> 2 C 0.
#> 3 z 1.00 Created on 2018-03-26 by the reprex package (v0.2.0). |
And this on @krlmlr code: suppressPackageStartupMessages(library(dplyr))
# User code:
df_f <- data_frame(a = factor(c("a", "C", "z")))
df_s <- data_frame(a = c("a", "C", "z"))
print(df_f %>% mutate(r = dense_rank(a)))
#> # A tibble: 3 x 2
#> a r
#> <fct> <int>
#> 1 a 1
#> 2 C 2
#> 3 z 3
print(df_s %>% mutate(r = dense_rank(a)))
#> # A tibble: 3 x 2
#> a r
#> <chr> <int>
#> 1 a 2
#> 2 C 1
#> 3 z 3 Created on 2018-03-26 by the reprex package (v0.2.0). |
Perhaps this was fixed as a side effect of something else @krlmlr ? |
Works for me now, even with v0.7.4 from CRAN. Victor, can you confirm? |
Hey @krlmlr, confirmed that it's now working for me on v0.7.4 from CRAN. |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
A follow-on from #2792, it appears many of the windowed ranking functions do not work on character columns when using tibbles.
The text was updated successfully, but these errors were encountered: