字符串的合并与分割

paste函数合并字符串

paste是一个字符串操作函数,可以把多个字符串合并为一个字符串
paste("xxxx","yyy") [1] "xxxx yyy"

strsplit函数分割字符串

strsplit("hello,world", ",")#两个参数第一个是要分割的字符串,第二个是分割条件这里是按逗号分割
[[1]]
[1] "hello" "world"


strsplit("hello world"," ")#两个参数第一个是要分割的字符串,第二个是分割条件这里是按空格分割
[[1]]
[1] "hello" "world"


strsplit("hello world","")#两个参数第一个是要分割的字符串,第二个是分割条件这里是逐字分割
[[1]]
[1] "h" "e" "l" "l" "o" " " "w" "o" "r" "l" "d"


x<-"xxxxx,yyhhh"
strsplit(x,"")
[[1]]
[1] "x" "x" "x" "x" "x" "," "y" "y" "h" "h" "h"

x<-rnorm(5) #随机生成5个正态分布数 y<-rnorm(5) z<-rnorm(5) a<-rnorm(5) b<-rnorm(5) d<-cbind(x,y,z,a,b)#按列拼接 M<-d*3#矩阵数乘 M%*%c(10,100,1000,10000,100000)#%*%是矩阵乘运算符号

你可能感兴趣的:(字符串的合并与分割)