当前位置:网站首页>strsplit()函数
strsplit()函数
2022-07-28 16:29:00 【皮肤科大白】
strsplit()函数
strsplit主要是根据子字符串中与此相匹配的字符将向量进行分割,分割后的内容不包含该字符的列表。
分割后的数据类型为列表
unlist(strsplit(test,split = ",")) ## 加unlist函数,后转化为字符串
R语言中常使用strsplit()函数对字符串进行分割。
语法
| 代码 | 参数 |
| strsplit(x, split, fixed = F, perl = F, useBytes = F) | x-字符串格式向量,函数依次对向量的每个元素进行拆分。 |
| split-为拆分位置的字串向量,即在哪个字串处开始拆分;该参数默认是正则表达式匹配。 | |
| fixed = T-表示是用普通文本匹配或者正则表达式的精确匹配。 | |
| perl-其设置和perl的版本有关,表示可以使用perl语言里面的正则表达式。如果正则表达式过长,则可以考虑使用perl的正则来提高运算速度。 | |
| useBytes-是否逐字节进行匹配,默认为FALSE,表示是按字符匹配而不是按字节进行匹配。 |
##设置fixed = T,正常拆分,参数作用为精确匹配,屏蔽正则表达式
> s <- '123 456'
> strsplit(s,'')
[[1]]
[1] "1" "2" "3" " " "4" "5" "6"
> strsplit(s, ' ')
[[1]]
[1] "123" "456"
> strsplit(s, ' ')[1]
[[1]]
[1] "123" "456"
> strsplit(s, ' ')[[1]][1]
[1] "123"
> x <- c(as = "asfef", qu = "qwerty", "yuiop[", "b", "stuff.blah.yech")
> x
as qu
"asfef" "qwerty" "yuiop[" "b" "stuff.blah.yech"
> strsplit(x, "e")
$as
[1] "asf" "f"
$qu
[1] "qw" "rty"
[[3]]
[1] "yuiop["
[[4]]
[1] "b"
[[5]]
[1] "stuff.blah.y" "ch"
> x = c("abcde", "ghij", "klmnopq") #x 为三个字条串组成的向量
> strsplit(x, "", fixed=TRUE) #用strsplit 把每个字符串中的字符给分离出来形成列表中单独的元素,总共有三个元素
[[1]]
[1] "a" "b" "c" "d" "e"
[[2]]
[1] "g" "h" "i" "j"
[[3]]
[1] "k" "l" "m" "n" "o" "p" "q"
3、指定输出结果为向量
> test <- "aa,bb,cc,dd,ee" ##生产测试数据
> a <- strsplit(test,split = ",")
> a
[[1]]
[1] "aa" "bb" "cc" "dd" "ee"
> class(a)
[1] "list"
> b <- unlist(strsplit(test,split = ",")) ## 加unlist函数
> b
[1] "aa" "bb" "cc" "dd" "ee"
> class(b)
[1] "character"
边栏推荐
- AMQP protocol details
- Create a custom paging control
- Embedded development learning path
- mmcv安装的办法
- Verilog daily question (vl14 vending machine 1 -- FSM common question types)
- [Presto] details of the new version upgrade of Presto
- The practice of beego framework in goweb development: Section I Introduction to beego framework
- The easy-to-use special app testing tool itest4.7.0 has been released
- With a total data volume of more than trillions of lines, Yuxi cigarette factory can easily deal with it by correctly selecting the timing database
- 异步电路设计--同步脉冲器原理及例题
猜你喜欢

Basic principle of asynchronous FIFO (simple implementation based on Verilog)

Verilog daily question (VL2 asynchronous reset Series T trigger - Niuke network)

PCA 报错Error in eigen(crossprod(t(X), t(X)), symmetric = TRUE) : ‘x‘里有无穷值或遗漏值

Wechat applet cash red packet returns the error "the IP address is not the available IP address you set on the merchant platform". The ultimate solution

在airtest中使用ocr反向识别文本内容

Verilog 每日一题(VL6 数据串转并电路)

Using OCR to reverse recognize text content in airtest

Verilog 每日一题 (VL28 加减计数器)

LNMP source code compilation and installation

连接设计与测试平台——SystemVerilog 接口知识点总结
随机推荐
AMQP protocol details
QR code generation of wechat applet with parameters
C # basic interview questions (with answers)
AMQP协议详解
Verilog 每日一题 (VL28 加减计数器)
Connection design and test platform -- Summary of SystemVerilog interface knowledge points
Solve the problem of exclusive SQL Server database
将input type='file' 类型的图片文件转成base64
Azure Devops developed by visual studio 2015 team
从非儿童网站看基线安全到底有多重要
Several methods of importing excel file data by C #
Convert multidimensional object array to one-dimensional array
循环中使用switch在执行条件后使用break和continue的区别
Verilog daily question (VL2 asynchronous reset Series T trigger - Niuke network)
C language to achieve minesweeping games
谈谈“发布后问题”的度量
Deploy lamp platform -- compilation and installation of Linux, Apache, MySQL and PHP
[Presto] details of the new version upgrade of Presto
The easy-to-use special app testing tool itest4.7.0 has been released
The practice of the beego framework for goweb development: Section V project construction and user registration