4
3

More than 5 years have passed since last update.

R で文字列の contains #rstatsj

Last updated at Posted at 2014-04-07

grepl() でできる。

carriers <- c("ezweb","docomo","softbank","vodafone")
grepl("o", carriers)
grepl("e", carriers)
結果
[1] FALSE  TRUE  TRUE  TRUE
[1]  TRUE FALSE FALSE  TRUE

文字列操作は stringr パッケージが便利なので、stringr::str_detect() を使ったほうが良い。

library(stringr)
carriers <- c("ezweb","docomo","softbank","vodafone")
str_detect(carriers, "o")
str_detect(carriers, "e")

参考:stringr — Rの文字列をまともな方法で処理する

4
3
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
4
3