在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
R语言中的字符处理(2011-07-10 22:29:48)R的字符串处理能力还是很强大的,具体有base包的几个函数和stringr包。
1.计算字符串的字符数
nchar()
paste(..., =====================================
> paste(letters[1:5], "_1", sep = '')
[1] "a_1" "b_1" "c_1" "d_1" "e_1"
> paste(letters[1:5], collapse='_')
[1] "a_b_c_d_e"
=====================================3. 字符串分割
3.1 分隔符截取 strsplit(x, ================================================================================= QWE <- c("QWERTYUIOPASDFGHJKLZXCVB > unlist(strsplit(QWE, "")) [20] "Z" "X" "C" "V" "B" "N" "M" > xtest [13] "11:53:13" "12:53:13" "13:53:13" "14:53:13" "15:53:13" "16:53:13" [19] "17:53:13" "18:53:13" "19:53:13" "20:53:13" "21:53:13" "22:53:13" [25] "23:53:14" > xtest <- as.data.frame(strsplit(xtest, split= ":")) > xtest 1 2 3 1 |