当前位置:网站首页>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"
边栏推荐
- 异步FIFO基本原理(基于Verilog的简单实现)
- 高速电路设计实践——概述
- Zero foundation uses unity3d to develop AR applications and download 3D models remotely
- JDWP未授权快速利用
- Why do I choose to use go language?
- PCA 报错Error in eigen(crossprod(t(X), t(X)), symmetric = TRUE) : ‘x‘里有无穷值或遗漏值
- 【presto】presto 常用的命令
- Linear algebra and matrix theory (VIII)
- Verilog 每日一题(VL2 异步复位的串联T触发器--牛客网)
- Verilog daily question (vl27 settable counter)
猜你喜欢

Arya-专业web自动化测试平台

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

一文掌握 JVM 面试要点

连接设计与测试平台——SystemVerilog 接口知识点总结

漫谈测试平台—平台建设思路(上)

No interactive operation of shell script
![[CDH] configure CDH components through clouderamanager and collect JMX information with Prometheus monitoring](/img/6a/bbc1ab0cfae9139308da4ded1376a8.png)
[CDH] configure CDH components through clouderamanager and collect JMX information with Prometheus monitoring

Gray code and binary conversion and typical examples (4bits gray code counter)

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

The easy-to-use special app testing tool itest4.7.0 has been released
随机推荐
Firewall protective wall
技术面轻松通过,HR:只有三年大厂经验的不值20K
【presto】presto 常用的命令
The practice of beego framework developed by goweb: Section 4 database configuration and connection
Selection of resistance in high speed circuit
JVM性能调优
mmcv安装的办法
Azure Devops developed by visual studio 2015 team
Esp-mqtt-at instruction connects Alibaba cloud Internet of things platform
一文掌握 JVM 面试要点
SNAT、DNAT 防火墙规则的备份和还原
js将本地时间与服务器时间同步
[atlas] atlas compilation error sorting (all)
Mysql database development specification
Verilog daily question (vl24 multi bit MUX synchronizer cross time domain output)
Jdwp unauthorized rapid utilization
Easy to use vscode plug-in memo
Linear algebra and matrix theory (VIII)
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
[kibana] problem sorting kibana 7.x no indices match pattern "APM-*“