加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

R之字符串相关

发布时间:2020-12-16 00:23:30 所属栏目:大数据 来源:网络整理
导读:1.strsplit(m,n)? 分割字符串:将字符串m,在含有字符n的地方进行分割 ?? 如:strsplit("abcdef","e"):?? 结果为: [[1]] [1] "abcd" "f"? ? strsplit(c("ab","cde","mnd"),"e")? 结果为: [[1]] [1] "ab" [[2]] [1] "cd" [[3]] [1] "mnd" ? 2.substr(m,index1

1.strsplit(m,n)? 分割字符串:将字符串m,在含有字符n的地方进行分割

?? 如:strsplit("abcdef","e"):??

结果为:

[[1]]
[1] "abcd" "f"?

?

strsplit(c("ab","cde","mnd"),"e")? 结果为:

[[1]]
[1] "ab"

[[2]]
[1] "cd"

[[3]]
[1] "mnd"

?

2.substr(m,index1,length):截取字符串m,从index1索引处截取长度为length的字符串;

> substr("abcde",1,3)
[1] "abc"

?

#字符串连接:
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, stop) <- value
substring(text,last = 1000000) <- value

#字符串替换及大小写转换:
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,
???????? ignore.case = FALSE,perl = FALSE,
???????? fixed = FALSE,useBytes = FALSE)

???? gsub(pattern,
????????? ignore.case = FALSE,
????????? fixed = FALSE,useBytes = FALSE)

???? regexpr(pattern,text, ignore.case = FALSE,
???????????? perl = FALSE,useBytes = FALSE)

???? gregexpr(pattern,
????????????? perl = 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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读