zoukankan      html  css  js  c++  java
  • R字符串处理

    R 字符串处理
    
    1 #字符串连接:
    paste() #paste(..., sep = " ", collapse = NULL)
    > paste("a","b","c",sep=">")
    [1] "a>b>c"
    2 字符串分割:
    strsplit() #strsplit(x, split, extended = TRUE, fixed = FALSE, perl = FALSE)
    > strsplit("a>b>c",">")
    [[1]]
    [1] "a" "b" "c"
    3 #计算字符串的字符数:
    nchar()
    > nchar("a>b>c")
    [1] 5
    4 #字符串截取:
    substr(x, start, stop)
    > paste("a","b","c",sep=">")->mm
    > substr(mm, 1, 3)
    [1] "a>b"
    substring(text, first, last = 1000000L)
    > substring(mm, 1, 3)
    [1] "a>b"
    > substring(mm,1,1:3)
    [1] "a"   "a>"  "a>b"
    解释
    1代表从第一个字母开始
    1:3代表取(1,1),(1,2),(1,3)
    substr(x, start, stop) <- value
    以下是进行字符串的替换
    substring(text, first, last = 1000000) <- value
    #字符串替换及大小写转换:
    chartr(old, new, x)
    > chartr("a","dd",mm)
    [1] "d>b>c"
    注:只能替换相同的字符数
    toupper(x)
    > toupper(mm)
    [1] "A>B>C"
    tolower(x)
    > tolower(mm)
    [1] "a>b>c"
    casefold(x, upper = TRUE)
    > casefold(mm, upper = TRUE)
    [1] "A>B>C"
    红色的起着重要作用.FALSE的话就还是和以前一样了
  • 相关阅读:
    简历的快速复制
    使用stringstream对象简化类型转换
    猴子吃桃
    new和delete运算符
    绘制正余弦曲线
    计算学生的平均成绩
    判断是否为回文字符串
    统计各种字符个数
    验证用户名
    回溯法(挑战编程)
  • 原文地址:https://www.cnblogs.com/blueicely/p/2966556.html
Copyright © 2011-2022 走看看