Global Search and Replace for Data.frames
Performs in-place editing of data.frames that have factor columns while correcting for the change to levels.
gsr(field,old,new)
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 |
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.
a factor vector
The function is designed to make simple editing changes to data.frames or factor vectors, resetting the levels appropriately.
data(brycesite) brycesite$quad <- gsr(brycesite$quad, old=c('bp','bc','pc','rp','tc','tr'), new=c('BP','BC','PC','RP','TC','TR'))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.