Learn R Programming

do (version 2.0.0.1)

Replace_ex: Replace Exactly

Description

Replace Exactly

Usage

Replace_ex(x, from, to, pattern)

Value

replaced data

Arguments

x

vector, dataframe or matrix

from

replaced stings

to

replacements

pattern

a special pattern, see examples for detail

Examples

Run this code
a=c(1,2,3,1,4)
Replace_ex(x = a,from = c(1,2),to=5)
Replace_ex(x=a,pattern = c('1:5','2:5'))
Replace_ex(x=a,pattern = '[12]:5')


a=data.frame(v=c(1,2,3,2,4),
             b=c(7,8,9,4,6))
Replace_ex(x = a,from = c(1,2),to=5)
Replace_ex(x=a,pattern = c('1:5','2:5'))

Run the code above in your browser using DataLab