Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

combine-factor-9x

Combine factor levels


Description

Convenience function to make it easy to combine multiple levels

Usage

combine_factor(fac, variable=levels(fac), other.label="Other")

Arguments

fac

factor variable

variable

either a vector of . See examples for more details.

other.label

label for other level

Author(s)

Hadley Wickham <h.wickham@gmail.com>

Examples

df <- data.frame(a = LETTERS[sample(5, 15, replace=TRUE)], y = rnorm(15))  
combine_factor(df$a, c(1,2,2,1,2))
combine_factor(df$a, c(1:4, 1))
(f <- reorder(df$a, df$y))
percent <- tapply(abs(df$y), df$a, sum)
combine_factor(f, c(order(percent)[1:3]))

reshape

Flexibly Reshape Data

v0.8.8
MIT + file LICENSE
Authors
Hadley Wickham [aut, cre]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.