字符串处理函数 R语言
来源:互联网 发布:vb中的标准模块是什么 编辑:程序博客网 时间:2024/05/22 07:06
用于字符串分割的函数:
如
strsplit('123abcdefgabcdef','ab')
[[1]]
[1] "123" "cdefg" "cdef"
#字符串连接:
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)
substring("abcdef",1:6,1:6)## strsplit is more efficient ...
substr(rep("abcdef",4),1:4,4:5)
x <- c("asfef", "qwerty", "yuiop[", "b", "stuff.blah.yech")
substr(x, 2, 5)substring(x, 2, 4:6)
substring(x, 2) <- c("..", "+++")
x
###########
#字符串替换及大小写转换:
chartr(old, new, x)
tolower(x)
toupper(x)
casefold(x, upper = FALSE)
字符完全匹配
grep()
字符不完全匹配
agrep()
字符替换
gsub()
#以上这些函数均可以通过perl=TRUE来使用正则表达式。
grep(pattern, x, ignore.case = FALSE, extended = TRUE,
perl = FALSE, value = FALSE, fixed = FALSE, useBytes = FALSE)
sub(pattern, replacement, x,
ignore.case = FALSE, extended = TRUE, perl = FALSE,
fixed = FALSE, useBytes = FALSE)
gsub(pattern, replacement, x,
ignore.case = FALSE, extended = TRUE, perl = FALSE,
fixed = FALSE, useBytes = FALSE)
regexpr(pattern, text, ignore.case = FALSE, extended = TRUE,
perl = FALSE, fixed = FALSE, useBytes = FALSE)
gregexpr(pattern, text, ignore.case = FALSE, extended = TRUE,
perl = FALSE, fixed = FALSE, useBytes = FALSE)
See Also:
regular expression (aka 'regexp') for the details of the pattern
specification.
'glob2rx' to turn wildcard matches into regular expressions.
'agrep' for approximate matching.
'tolower', 'toupper' and 'chartr' for character translations.
'charmatch', 'pmatch', 'match'. 'apropos' uses regexps and has
nice examples.
暂时就这么多吧。找到以后再粘贴上。
如
strsplit('123abcdefgabcdef','ab')
[[1]]
[1] "123" "cdefg" "cdef"
#字符串连接:
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)
substring("abcdef",1:6,1:6)## strsplit is more efficient ...
substr(rep("abcdef",4),1:4,4:5)
x <- c("asfef", "qwerty", "yuiop[", "b", "stuff.blah.yech")
substr(x, 2, 5)substring(x, 2, 4:6)
substring(x, 2) <- c("..", "+++")
x
###########
#字符串替换及大小写转换:
chartr(old, new, x)
tolower(x)
toupper(x)
casefold(x, upper = FALSE)
字符完全匹配
grep()
字符不完全匹配
agrep()
字符替换
gsub()
#以上这些函数均可以通过perl=TRUE来使用正则表达式。
grep(pattern, x, ignore.case = FALSE, extended = TRUE,
perl = FALSE, value = FALSE, fixed = FALSE, useBytes = FALSE)
sub(pattern, replacement, x,
ignore.case = FALSE, extended = TRUE, perl = FALSE,
fixed = FALSE, useBytes = FALSE)
gsub(pattern, replacement, x,
ignore.case = FALSE, extended = TRUE, perl = FALSE,
fixed = FALSE, useBytes = FALSE)
regexpr(pattern, text, ignore.case = FALSE, extended = TRUE,
perl = FALSE, fixed = FALSE, useBytes = FALSE)
gregexpr(pattern, text, ignore.case = FALSE, extended = TRUE,
perl = FALSE, fixed = FALSE, useBytes = FALSE)
See Also:
regular expression (aka 'regexp') for the details of the pattern
specification.
'glob2rx' to turn wildcard matches into regular expressions.
'agrep' for approximate matching.
'tolower', 'toupper' and 'chartr' for character translations.
'charmatch', 'pmatch', 'match'. 'apropos' uses regexps and has
nice examples.
暂时就这么多吧。找到以后再粘贴上。
有知道的朋友可以跟帖发上
转自:http://www.biostatistic.net/thread-195-1-1.html
0 0
- 字符串处理函数 R语言
- R 语言 字符串处理常用函数
- R语言处理字符串
- 【R语言】字符串处理
- [R语言]字符串处理
- R语言-字符串处理
- R-字符串处理函数
- R语言之——字符串处理函数
- R语言字符串处理相关
- R语言字符串处理总结
- R 中字符串处理函数
- R语言时间处理函数
- R语言字符串处理函数之——字符串的大小写转换
- R语言学习之字符串处理
- 拆解字符串并逐个处理 R语言
- R语言字符串处理(2)
- R语言-用stringr包处理字符串
- R语言学习-对象处理实用函数
- 算法导论 改进快排(1)----几乎有序的序列 7.4-5
- NSString属性什么时候用copy,什么时候用strong?
- jQuery之简单的表单验证
- 白话经典算法系列之三 希尔排序的实现
- linux下进入终端的几种方式
- 字符串处理函数 R语言
- EXTJS4.2数据源配置及创建注意事项
- 集成微信接口开发
- Android学习 - 自定义输入法
- 【学习笔记】JavaScript编码规范-变量
- leveldb之文件
- 关于获取本机ip的问题
- druid ehcache
- 如何更改linux下的Apache端口号