stringr包中的重要函數
| 函數 | 功能說明 | R Base中對應函數 |
|---|---|---|
| 使用正則表達式的函數 | ||
str_extract() |
提取首個匹配模式的字符 | regmatches() |
str_extract_all() |
提取所有匹配模式的字符 | regmatches() |
str_locate() |
返回首個匹配模式的字符的位置 | regexpr() |
str_locate_all() |
返回所有匹配模式的字符的位置 | gregexpr() |
str_replace() |
替換首個匹配模式 | sub() |
str_replace_all() |
替換所有匹配模式 | gsub() |
str_split() |
按照模式分割字符串 | strsplit() |
str_split_fixed() |
按照模式將字符串分割成指定個數 | - |
str_detect() |
檢測字符是否存在某些指定模式 | grepl() |
str_count() |
返回指定模式出現的次數 | - |
| 其他重要函數 | ||
str_sub() |
提取指定位置的字符 | regmatches() |
str_dup() |
丟棄指定位置的字符 | - |
str_length() |
返回字符的長度 | nchar() |
str_pad() |
填補字符 | - |
str_trim() |
丟棄填充,如去掉字符前后的空格 | - |
str_c() |
連接字符 | paste(),paste0() |
