Filter a vector of strings based on string matching

后端 未结 4 1173
[愿得一人]
[愿得一人] 2020-12-30 19:43

I have the following vector:

X <- c(\"mama.log\", \"papa.log\", \"mimo.png\", \"mentor.log\")

How do I retrieve another vector that only

4条回答
  •  北海茫月
    2020-12-30 20:41

    Using pipes...

    library(tidyverse)
    
    c("mama.log", "papa.log", "mimo.png", "mentor.log") %>%
     .[grepl("^m.*\\.log$", .)]
    [1] "mama.log"   "mentor.log"
    

提交回复
热议问题