いずれかを含むベクトル内の名前を見つけることは可能ですか
id
または
group
または、以下の例の両方ですか?
利用した
grepl()
成功せずに。
a = c("c-id" = 2, "g_idgroups" = 3, "z+i" = 4)
grepl(c("id", "group"), names(a)) # return name of elements that contain either `id` OR `group` OR both
回答 2 件
str_detectの使用:
> names(a)[str_detect(names(a), 'id|groups')] [1] "c-id" "g_idgroups" > names(a) [1] "c-id" "g_idgroups" "z+i" >
あなたが使用することができます:
と
grepl
あなたは論理値を得ることができますA
stringr
解決 :