split.string<-function(string){
str2<-strsplit(string,"")[[1]]
string.split<-NULL
j<-1
string.split[j]<-str2[1]
find.type<-function(char){
if(grepl("[[:alpha:]]",char))
type<-"alphabet"
else if(grepl("[[:digit:]]",char))
type<-"digit"
else type<-"chinese"
type
}
type<-find.type(str2[1])
for(i in 2:length(str2)){
type2<-find.type(str2[i])
if(type2==type) string.split[j]<-paste(string.split[j],str2[i],sep="")
else{
j<-j+1
type<-type2
string.split<-c(string.split,str2[i])
}
}
string.split
}
直接跑
split.string("中国123abc")
就好了
如果要区分更多的东西,就改一下内部的find.type()函数。我现在写的只能区分字母、数字和其他东西(比如标点和中文就分不开了)
1/3。R是实数,实数三分之一用斜杠表示为1/3。
R是用于统计分析、绘图的语言和操作环境。R是属于GNU系统的一个自由、免费、源代码开放的软件,它是一个用于统计计算和统计制图的优秀工具。
就是一个编号,没啥意思,举个例子>c<-1:90
>c
显示结果是:
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
[25] 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
[49] 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
[73] 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
前面的“[N]”就是表示本行第一元素是向量c的第N个元素。