主頁:https://cran./web/packages/stringr/index.html #安裝stringr包> install.packages('stringr') > library(stringr) #stringr函數分類: 字符串拼接函數 字符串計算函數 字符串匹配函數 字符串變換函數 參數控制函數 #stringr字符串變換函數 str_conv(string, encoding) string: 字符串,字符串向量,。 encoding: 編碼名,。 對中文進行轉碼處理。 # 把中文字符字節(jié)化 > x <- charToRaw('你好');x [1] c4 e3 ba c3 # 默認win系統(tǒng)字符集為GBK,,GB2312為GBK字集,,轉碼正常 > str_conv(x, "GBK") [1] "你好" > str_conv(x, "GB2312") [1] "你好" # 轉UTF-8失敗 > str_conv(x, "UTF-8") [1] "???" Warning messages: 1: In stri_conv(string, encoding, "UTF-8") : input data \xffffffc4 in current source encoding could not be converted to Unicode 2: In stri_conv(string, encoding, "UTF-8") : input data \xffffffe3\xffffffba in current source encoding could not be converted to Unicode 3: In stri_conv(string, encoding, "UTF-8") : input data \xffffffc3 in current source encoding could not be converted to Unicode 把unicode轉UTF-8 > x1 <- "\u5317\u4eac" > str_conv(x1, "UTF-8") [1] "北京" |
|