Replacing an entire string with one single letter in R -


i have data set in need rename every data "kas" every instance of kasaragod in column. need replace entire thing in column "kas" if instance found.

p o, pin: 671543,kasaragod kas

what command should use?

sample data:

g05 g06 g07 g08 g09 g10 address_2   a+  a+  a+  a+  a+  kumbadaje p o, pin: 671551, kasaragod   b   b   b+      mallam p o, pin: 671542, kasaragod b+  b   b+  a+  c+  b+  kumbadaje p o, pin: 671551, kasaragod b+  b+  b   b+    a+  movvar p o, pin: 671543, kasaragod b   b   b   b+  a+  a+  movvar p o, pin: 671543, kasaragod a+  a+  a+  a+  a+  a+  movvar p o, pin: 671543, kasaragod b+  b+  b     b+    yethadka p o, pin: 671551, kasaragod c   c   c   c   c     movvar p o, pin: 671543, kasaragod a+  a+  a+  a+  a+  a+  movvar p o, pin: 671543, kasaragod 

my first thought gsub. if data frame called edu, try

edu$address_2 <- gsub(".*kasaragod.*", "kas", edu$address_2) 

this give

g05 g06 g07 g08 g09 g10 address_2    a+  a+  a+  a+  a+       kas     b   b  b+           kas  b+   b  b+  a+  c+  b+       kas  b+  b+   b  b+    a+       kas   b   b   b  b+  a+  a+       kas  a+  a+  a+  a+  a+  a+       kas  b+  b+   b    b+         kas   c   c   c   c   c         kas  a+  a+  a+  a+  a+  a+       kas 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -