字符串长度:

nchar("hello world")

#字符串连接:
paste() #paste(..., sep = " ", collapse = NULL)

#字符串分割:
strsplit() #strsplit(x, split, extended = TRUE, fixed = FALSE, perl = FALSE)

aa<-unlist(strsplit(x, 'char'))

aa[1] # first string

#计算字符串的字符数:
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 字符串替换

## 包含子字符串: chars中是否包含value

grepl(value, chars) # chars contains value? (TRUE, FALSE)

#字符串比较:

if(as.character(x)==as.character(y))

判断字符串是否包含某个子串
> chars <- "test"
> value <- "es"
> grepl(value, chars)

R语言字符串函数的更多相关文章

  1. C语言字符串函数大全

    C语言字符串函数大全 函数名: stpcpy 功 能: 拷贝一个字符串到另一个 用 法: char *stpcpy(char *destin, char *source); 程序例: #include ...

  2. 【R】R语言常用函数

    R语言常用函数 基本 一.数据管理vector:向量 numeric:数值型向量 logical:逻辑型向量character:字符型向量 list:列表 data.frame:数据框c:连接为向量或 ...

  3. 13-C语言字符串函数库

    目录: 一.C语言字符串函数库 二.用命令行输入参数 回到顶部 一.C语言字符串函数库 1 #include <string.h> 2 字符串复制 strcpy(参数1,参数2); 参数1 ...

  4. R语言table()函数

    R语言table()函数比较有用,两个示例尤其是混淆矩阵这个案例比较有用: 例子一:统计频次 z<-c(1,2,2,4,2,7,1,1);z1<-table(z);summary(z1); ...

  5. R语言封装函数

    R语言封装函数 原帖见豆瓣:https://www.douban.com/note/279077707/ 一个完整的R函数,需要包括函数名称,函数声明,函数参数以及函数体几部分. 1. 函数名称,即要 ...

  6. R语言常用函数:交集intersect、并集union、找不同setdiff、判断相同setequal

    在R语言进行数据分析时,经常需要找不同组间的相同和不同,那你应该掌握如下几个函数,让你事半功倍. 交集intersect两个向量的交集,集合可以是数字.字符串等 # 两个数值向量取交集intersec ...

  7. C语言字符串函数例子程序大全 – string相关

    关于字符串函数的应用细则,例子程序 – jerny 函数名: stpcpy 功 能: 拷贝一个字符串到另一个 用 法: char *stpcpy(char *destin, char *source) ...

  8. R语言中函数调试

    有时候会用R语言写一下简单的脚本处理函数,加入需要调试的话可以按照下面的步骤进行: fun <- function(x , y){ x + y x - y x * y x / y } debug ...

  9. .net 调用R语言的函数(计算统计值pvalue 对应excel :ttest)

    Pvalue 计算 项目设计pvalue计算,但是由于.net 没有类似的公式或者函数,最终决定使用.net 调用R语言 采用.net 调用r语言的公用函数 需要安装 r语言环境 https://mi ...

随机推荐

  1. Install mcrypt for php on Mac OSX 10.10 Yosemite for a Development Server

    mcrypt is a file encryption method using secure techniques to exchange data. It is required for some ...

  2. TCP/IP, HTTP, socket

    摘自:http://jingyan.baidu.com/article/08b6a591e07ecc14a80922f1.html http://goodcandle.cnblogs.com/arch ...

  3. 利用getchar()消除多余字符数据(主要是“回车”)

  4. Bluetooth

    Android provides a default Bluetooth stack, BlueDroid, that is divided into two layers: The Bluetoot ...

  5. 双倍边距bug

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  6. 让站长在SEO时更得心应手的六个细节

    分析一下SEO的心得,希望能对很多做网站优化和做网站推广的站长有帮助,现在做SEO的人越来网站推广越多,即使很多人在做,但不知道自己能否成功,自己的优化是否会见效,所以在这里还是来分享一下咱们在SEO ...

  7. ajax与jsonp的区别

    ajax的核心是通过XmlHttpRequest获取非本页内容,而jsonp的核心则是动态添加<script>标签来调用服务器提供的js脚本.

  8. C#中Json和List/DataSet相互转换

    #region List<T> 转 Json        /// <summary>        /// List<T> 转 Json        /// & ...

  9. 【WCF--初入江湖】06 WCF契约服务行为和异常处理

    06 WCF契约服务行为和异常处理 一.WCF契约服务行为 [1] 服务行为可以修改和控制WCF服务的运行特性. 在实现了WCF服务契约后,可以修改服务的很多执行特性. 这些行为(或者特性)是通过配置 ...

  10. selenium实战脚本集——新浪微博发送QQ每日焦点(火狐)

    selenium实战脚本集(1)——新浪微博发送QQ每日焦点,乙醇用谷歌实现的,下边是用火狐实现的. 代码如下: # coding = utf-8 from selenium import webdr ...