R語言學習筆記(八):stringr

匯入套件

library(stringr)

大小寫轉換

str_to_upper(string)    #轉大寫
str_to_lower(string) #轉小寫
str_to_title(string) #轉成標題

字串處理

str_trim(string)                              #刪除空白
str_sub(string, start = 1L, end = -1L) #萃取字串的一部分
str_replace(string, pattern, replacement) #取代字串
#例子
fruit <- c("apple", "banana", "pear", "pinapple")
str_detect(fruit, "a")
[1] TRUE TRUE TRUE TRUE
which(str_detect(fruit, "a"))
[1] "apple" "banana" "pear" "pinapple"

更多使用方式:

Written by

Machine Learning / Deep Learning / Python / Flutter cakeresume.com/yanwei-liu

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store