Skip to contents

like rank() with ties.method = "max", works on tbl objects

Usage

max_rank(df, col, col_new)

Arguments

df

dataframe

col

character column name to rank y

col_new

character column name for rankings

Details

this is needed for hochberg p value adjustment. We need to assign higher rank when multiple sites have same p value

Examples


df <- tibble::tibble(s = c(1, 2, 2, 2, 5, 10)) %>%
 dplyr::mutate(
   rank = rank(s, ties.method = "max")
 )

df %>%
 max_rank("s", "max_rank")
#> # A tibble: 6 × 3
#>       s  rank max_rank
#>   <dbl> <int>    <int>
#> 1     1     1        1
#> 2     2     4        4
#> 3     2     4        4
#> 4     2     4        4
#> 5     5     5        5
#> 6    10     6        6
# \donttest{
# Database
con <- DBI::dbConnect(duckdb::duckdb(), dbdir = ":memory:")

dplyr::copy_to(con, df, "df")
max_rank(dplyr::tbl(con, "df"), "s", "max_rank")
#> # Source:   SQL [6 x 3]
#> # Database: DuckDB v1.0.0 [koneswab@Darwin 23.6.0:R 4.4.1/:memory:]
#>       s  rank max_rank
#>   <dbl> <int>    <dbl>
#> 1     2     4        4
#> 2     2     4        4
#> 3     2     4        4
#> 4     5     5        5
#> 5    10     6        6
#> 6     1     1        1

DBI::dbDisconnect(con)
# }