Skip to content

including mode for the distribution in describe_distribution #160

@IndrajeetPatil

Description

@IndrajeetPatil

Saw some discussion on Twitter about how base-R doesn't have a function to calculate mode. So was wondering if it might be a good idea for us to include this info.

library(parameters)

describe_distribution(mtcars$wt)
#> Mean |   SD |  IQR |        Range | Skewness | Kurtosis |  n | n_Missing
#> ------------------------------------------------------------------------
#> 3.22 | 0.98 | 1.19 | [1.51, 5.42] |     0.47 |     0.42 | 32 |         0

getmode <- function(v) {
  uniqv <- unique(v)
  uniqv[which.max(tabulate(match(v, uniqv)))]
}

Created on 2021-06-03 by the reprex package (v2.0.0)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions