gsr {labdsv} | R Documentation |
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)
David W. Roberts droberts@montana.edu
Examples
data(brycesite)
brycesite$quad <- gsr(brycesite$quad,
old=c('bp','bc','pc','rp','tc','tr'),
new=c('BP','BC','PC','RP','TC','TR'))
[Package labdsv version 2.1-0 Index]