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

gsr

Global Search and Replace for Data.frames


Description

Performs in-place editing of data.frames that have factor columns while correcting for the change to levels.

Usage

gsr(field,old,new)

Arguments

field

a vector or specific column in a data.frame

old

a character vector of values to search for

new

a character vector of values to replace the respective items in old

Details

The function temporarily converts a vector or vector column in a data.frame to a character vector, and then loops through the ‘old’ vector looking for values to replace with the respective value in the ‘new’ vector. The column is then converted back to a factor.

Value

a factor vector

Note

The function is designed to make simple editing changes to data.frames or factor vectors, resetting the levels appropriately.

Author(s)

Examples

data(brycesite)
brycesite$quad <- gsr(brycesite$quad,
    old=c('bp','bc','pc','rp','tc','tr'),
    new=c('BP','BC','PC','RP','TC','TR'))

labdsv

Ordination and Multivariate Analysis for Ecology

v2.0-1
GPL (>= 2)
Authors
David W. Roberts <droberts@montana.edu>
Initial release

We don't support your browser anymore

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