R语言字符串函数
2014-02-04 15:23
369 查看
字符串长度:
nchar("hello world")
#字符串连接:
paste() #paste(..., sep = " ", collapse = NULL)
#字符串分割:
strsplit() #strsplit(x, split, extended = TRUE, fixed = FALSE, perl = FALSE)
#计算字符串的字符数:
nchar()
#字符串截取:
substr(x, start, stop)
substring(text, first, last = 1000000)
substr(x, start, stop) <- value
substring(text, first, last = 1000000) <- value
substr("abcdef", 2, 4)
[1] "bcd"
#字符串替换及大小写转换:
chartr(old, new, x)
tolower(x)
toupper(x)
casefold(x, upper = FALSE)
#字符串比较:
nchar("hello world")
#字符串连接:
paste() #paste(..., sep = " ", collapse = NULL)
#字符串分割:
strsplit() #strsplit(x, split, extended = TRUE, fixed = FALSE, perl = FALSE)
#计算字符串的字符数:
nchar()
#字符串截取:
substr(x, start, stop)
substring(text, first, last = 1000000)
substr(x, start, stop) <- value
substring(text, first, last = 1000000) <- value
substr("abcdef", 2, 4)
[1] "bcd"
> x <- "1234567890" > substr(x, 3, 3) [1] "3" > > substr(x, 5, 7) [1] "567" > > substr(x, 4, 4) <- "A" > x [1] "123A567890" > > substr(x, 2, 4) <- "TTF" > x [1] "1TTF567890" > > substr(x, 9, 12) <- "ABCD" > x [1] "1TTF5678AB" > > substring(x, 5) [1] "5678AB" > > substring(x, 5) <- "..." > x [1] "1TTF...8AB"
#字符串替换及大小写转换:
chartr(old, new, x)
tolower(x)
toupper(x)
casefold(x, upper = FALSE)
x=gsub(old_strin, new_string, x) # replace string 字符串替换
grepl(value, chars)# chars contains value? (TRUE, FALSE)
#字符串比较:
if(as.character(x)==as.character(y))
相关文章推荐
- 使用图形界面调试arm程序: insight + gdb
- 正式在CSDN开博
- XMLPULL解析(2)---通过对象序列化生成XML文档
- UVA 424和10106的个人体会
- POJ 2486 经典树形dp
- LockDemo
- 安装debian linux后的优化配置
- Linux内核编译,模块尺寸变大的解决办法
- 程序员必看的那些电影
- Initialising Memories
- tomcat的一些设置
- java学习之面试题3
- SPOJ 220 Relevant Phrases of Annihilation(后缀数组)
- 2014学习计划
- 【C++学习】迭代器的使用:vector的操作---ShinePans
- Uml 9种图 之 行为描述 之活动图和状态图
- 《CSS Mastery》读书笔记(3)
- Cracking the coding interview--Q2.1
- 《CSS Mastery》读书笔记(2)
- UiButton操作