rank_df {COINr}R Documentation

Convert a data frame to ranks

Description

Replaces all numerical columns of a data frame with their ranks. Uses sport ranking, i.e. ties share the highest rank place. Ignores non-numerical columns. See rank(). Optionally, returns in-group ranks using a specified grouping column.

Usage

rank_df(df, use_group = NULL)

Arguments

df

A data frame

use_group

An optional column of df (specified as a string) to use as a grouping variable. If specified, returns ranks inside each group present in this column.

Details

This function replaces the now-defunct rankDF() from COINr < v1.0.

Value

A data frame equal to the data frame that was input, but with any numerical columns replaced with ranks.

Examples

# some random data, with a column of characters
df <- data.frame(RName = c("A", "B", "C"),
Score1 = runif(3), Score2 = runif(3))
# convert to ranks
rank_df(df)
# grouped ranking - use some example data
df1 <- ASEM_iData[c("uCode", "GDP_group", "Goods", "LPI")]
rank_df(df1, use_group = "GDP_group")


[Package COINr version 1.1.7 Index]