Learn R Programming

SciencesPo (version 0.3.8.27)

gsr: Global Search and Replace

Description

The function performs search and replace.

Usage

gsr(file, search, replace)

Arguments

file
is a vector or a data.frame.
search
is the item to be replaced.
replace
is the new item or value to be attributed.

Value

  • An object of the same type as file.

References

http://danielmarcelino.com/SciencePo

Examples

Run this code
# First example: generate some raw data

data <- data.frame( 
	i=i <- rep(1, len = 100),
	t=t<-sample(c('2008', '2012'), 100, replace=TRUE),
	p=p <- sample(LETTERS[1:3], 100, replace=TRUE),
	j=j <- sample(letters[1:13], 100, replace=TRUE) )

data$ide <-gsr(data$p, 
	c('A', 'B'), 
	c('Left', 'Centre'))

print(data)

Run the code above in your browser using DataLab