Learn R Programming

labdsv (version 2.1-0)

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)

Value

a factor vector

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

Author

David W. Roberts droberts@montana.edu

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.

Examples

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

Run the code above in your browser using DataLab