Quantcast
Channel: Data Science, Analytics and Big Data discussions - Topics tagged data_science
Viewing all articles
Browse latest Browse all 787

Multiple replacement in R

$
0
0

@premsheth wrote:

Hi,

I am trying to do multiple replacement with single function.
I want to replace some words with 1 category word
For example:
“Scrubs & Body Treatments”,"Exfoliators, Polishes & Scrubs ",“Scrubs & Body Treatments” these three words and now I want replace there name with "Scrub"
I tried to create function as follows:
myfun <- function(pattern,replacement,x){
result <- list()
for (i in 1:length(pattern)) {
result[i] <- gsub(pattern[i],replacement,x)
}
result
}
but its not working.
Thanks in Advance

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 787

Trending Articles