Skip to content

Integer overflow with ntile() and large tiles + numbers of records #4186

@krlmlr

Description

@krlmlr

#4185 (comment)

library(tidyverse)

tibble(a = 1:1e2) %>%
  mutate(b = ntile(n = 1e2)) %>%
  count(b) %>%
  tail()
#> # A tibble: 6 x 2
#>       b     n
#>   <int> <int>
#> 1    95     1
#> 2    96     1
#> 3    97     1
#> 4    98     1
#> 5    99     1
#> 6   100     1

tibble(a = 1:1e3) %>%
  mutate(b = ntile(n = 1e3)) %>%
  count(b) %>%
  tail()
#> # A tibble: 6 x 2
#>       b     n
#>   <int> <int>
#> 1   995     1
#> 2   996     1
#> 3   997     1
#> 4   998     1
#> 5   999     1
#> 6  1000     1

tibble(a = 1:1e4) %>%
  mutate(b = ntile(n = 1e4)) %>%
  count(b) %>%
  tail()
#> # A tibble: 6 x 2
#>       b     n
#>   <int> <int>
#> 1  9995     1
#> 2  9996     1
#> 3  9997     1
#> 4  9998     1
#> 5  9999     1
#> 6 10000     1

tibble(a = 1:1e5) %>%
  mutate(b = ntile(n = 1e5)) %>%
  count(b) %>%
  tail()
#> # A tibble: 6 x 2
#>       b     n
#>   <int> <int>
#> 1 21470     2
#> 2 21471     2
#> 3 21472     2
#> 4 21473     2
#> 5 21474     2
#> 6 21475     2

Created on 2019-02-15 by the reprex package (v0.2.1.9000)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions