Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
拆分R中特殊字符的列表/向量_R_Split - Fatal编程技术网

拆分R中特殊字符的列表/向量

拆分R中特殊字符的列表/向量,r,split,R,Split,假设我想拆分x,您应该可以使用以下工具来完成此操作: split(y,gsub("_\\d+$","",y)) 在这里,我们使用gsub(“\ud+$”,“”,y),从y中提取“\ucode>前面的第一个数字,创建一个因子。为了说明,假设y为: y <- c("1_1","1_2","1_11","1_100","2_1","2_2","2_11","2_100","3_1","3_2","3_11","3_100") split(y,gsub("_\\d+$","",y)) ##$`1

假设我想拆分
x,您应该可以使用以下工具来完成此操作:

split(y,gsub("_\\d+$","",y))
在这里,我们使用
gsub(“\ud+$”,“”,y)
,从
y
中提取
“\ucode>前面的第一个数字,创建一个
因子。为了说明,假设
y
为:

y <- c("1_1","1_2","1_11","1_100","2_1","2_2","2_11","2_100","3_1","3_2","3_11","3_100")
split(y,gsub("_\\d+$","",y))
##$`1`
##[1] "1_1"   "1_2"   "1_11"  "1_100"
##
##$`2`
##[1] "2_1"   "2_2"   "2_11"  "2_100"
##
##$`3`
##[1] "3_1"   "3_2"   "3_11"  "3_100"

y您应该能够通过以下方式完成此操作:

split(y,gsub("_\\d+$","",y))
在这里,我们使用
gsub(“\ud+$”,“”,y)
,从
y
中提取
“\ucode>前面的第一个数字,创建一个
因子。为了说明,假设
y
为:

y <- c("1_1","1_2","1_11","1_100","2_1","2_2","2_11","2_100","3_1","3_2","3_11","3_100")
split(y,gsub("_\\d+$","",y))
##$`1`
##[1] "1_1"   "1_2"   "1_11"  "1_100"
##
##$`2`
##[1] "2_1"   "2_2"   "2_11"  "2_100"
##
##$`3`
##[1] "3_1"   "3_2"   "3_11"  "3_100"
y