1
文字列のセット内の特定のパターンを検索したい。文字列のこれら二つのベクトルを考えるとR - grepを使った文字列の順序付けパターンを見つける
:
actions <- c("taking","using")
nouns <- c("medication","prescription")
を私は、この特定の順序でアクション + 名詞、ない名詞+アクションの任意の組み合わせを見つけたいです。薬を使用して
- 次のテキストを使用してprescritpionに
を使用して、薬物
phrases <- c("he was using medication",
"medication using it",
"finding medication",
"taking the left",
"using prescription medication",
"taking medication drug")
私はgrep("\\b(taking|using+medication|prescriptio)\\b",phrases,value = FALSE)
を使ってみましたが、明らかに間違っています。
'+'は、前のトークンを1回以上探すことを意味する量指定子です。 'grep(" take | using medication | prescription "、フレーズ)' – alistaire
'grep(paste0("))を試してみてください。 ( "、")、フレーズ、値= FALSE) '、http://を参照してください。 /ideone.com/e7Ae5S –
まだありませんが、私は*動作*だけで*名詞*はないので、4番目のフレーズを一致させたくありません。 –