LoginSignup
0
0

More than 5 years have passed since last update.

Rで正規表現に検索ワードと置換ワードをベクトルで指定する

Last updated at Posted at 2013-11-09

ベクトルそのものを使っているわけじゃないけど...

> library(gsubfn)
 要求されたパッケージ proto をロード中です 
 要求されたパッケージ tcltk をロード中です 

> # 検索ワードとその置き換えワードをベクトルとして指定する

> x1 <- c("宮内れんげ", "一条蛍", "越谷小鞠", "越谷卓", "越谷夏海")
> y <- list(夏 =  "秋", 小 = "大", れん = "げん")
> gsubfn("夏|小|れん", y, x1)
[1] "宮内げんげ" "一条蛍"     "越谷大鞠"   "越谷卓"     "越谷秋海"

> x2 <- c("宮内れんげ一条蛍越谷小鞠越谷卓越谷夏海")
> gsubfn("夏|小|れん", y, x2)
[1] "宮内げんげ一条蛍越谷大鞠越谷卓越谷秋海"

> # リストからパターンを作成
> y0 <- paste(names (y), collapse = "|")
> gsubfn(y0, y, x1)
[1] "宮内げんげ" "一条蛍"     "越谷大鞠"   "越谷卓"     "越谷秋海"  
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0