str_extract() 提取第一个匹配到的文本,并返回字符向量 str_extract_all() 提取所有匹配到的文本,返回一堆字符向量 # What are the phone numbers? str_extract(strings, phone) #> [1] NA "219 733 8965" "329-293-8753" "579-499-7527" str_extract_all(strings, phone) #> [[1]] #> character...
str_extract_all(string, pattern, simplify = FALSE) 1. 2. shopping_list <- c("apples x4", "bag of flour", "bag of sugar", "milk x2") str_extract(shopping_list, "[a-z]+") # 结果 [1] "apples" "bag" "bag" "milk" str_extract_all(shopping_list, "[a-z]+") # 结果 [[...
1.8 提取匹配到的字符 提取单个或是提取多个匹配到的字符串,使用str_extract_all()时,使用参数simplify = T x <- "The birch canoe slid on the smooth planks." x2 = str_split(x," ")[[1]];x2 str_extract(x2,"o|e") #[1] "e" NA "o" NA "o" "e" "o" NA #提取o或e,默认只提...
str_extract() 提取第一个匹配到的文本,并返回字符向量 str_extract_all() 提取所有匹配到的文本,返回一堆字符向量 # What are the phone numbers? str_extract(strings, phone) #> [1] NA "219 733 8965" "329-293-8753" "579-499-7527" str_extract_all(strings, phone) #> [[1]] #> character...