Skip to contents

From a data frame, returns the top n values from a named column based on the values in another column, and pastes them together in a grammatically correct string. Ideal for commentary which aims to describe e.g. "the top 3 values of X were for the following regions:"

Usage

top_x(df, n = 1, values = "value", names = "name")

Arguments

df

a dataframe of value-name pairs.

n

the number of values/names of interest; e.g. n = 3 will return a commentary discussing the top 3 values

values

column name of the column containing numerical values to sort top n values on. Defaults to "value".

names

column name of the column containing name values used to describe the top n values. Defaults to "name"

Value

Returns a string of name values for the top n values.