replace: Replace values in a vector

Description Usage Arguments Details Value Author(s) Examples

View source: R/replace.R

Description

Replace the values in a vector with a new value

Usage

1
replace(x, old.value, new.value, factor = F)

Arguments

x

The vector that has values that need replacing

old.value

The value that needs replacing

new.value

The value that will replace old.value

factor

Should the vector be "refactored" (so old values no longer show up as a factor level)?

Details

This function searches the vector provided for old.values, then replaces each occurance with new.values

Value

A new vector where old.values are replaced by new.values

Author(s)

Dustin Fife

Examples

1
2
3
4
d = data.frame(category = sample(c("Male", "Female", "Men"), prob=c(.45, .45, .05), size=100, replace=T))
table(d$category)
d$category = replace(d$category, "Men", "Male")
table(d$category)

dustinfife/fifer documentation built on Oct. 31, 2020, 3:36 p.m.