Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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_Loops_Vector_Character_Strsplit - Fatal编程技术网

R 如何从角色对象创建角色向量?

R 如何从角色对象创建角色向量?,r,loops,vector,character,strsplit,R,Loops,Vector,Character,Strsplit,我需要转换对象的字符类型,如: "1234" "1123" "0654" "0001" 对于向量,如: 1,2,3,4,1,1,2,3,0,6,5,4,0,0,0,1 我能够使用strsplit将for数字组中的每一个字符分开,但是我不能将它们添加到单个对象中 我使用的for循环: number_0 number_0_vect <- vector("list",1024) for (number in number_0){ line_vects <- strsplit(nu

我需要转换对象的字符类型,如:

"1234"
"1123"
"0654"
"0001"
对于向量,如:

1,2,3,4,1,1,2,3,0,6,5,4,0,0,0,1
我能够使用strsplit将for数字组中的每一个字符分开,但是我不能将它们添加到单个对象中

我使用的for循环:

number_0
number_0_vect <- vector("list",1024)

for (number in number_0){
  line_vects <- strsplit(number, "")[[1]]
  for (line_vect in line_vects){
    number_0_vect[line_vect] <- line_vect
  }
}
number\u 0
使用strsplit的数字向量:


x如果你不喜欢使用
unlist()
你可以先
粘贴
x
中的每个元素,然后使用
stringr::stru split

x <- c("1234", "1123", "0654", "0001")
as.numeric(stringr::str_split(paste(x, collapse = ""), "")[[1]])
#[1] 1 2 3 4 1 1 2 3 0 6 5 4 0 0 0 1
x
x <- c("1234", "1123", "0654", "0001")
as.numeric(stringr::str_split(paste(x, collapse = ""), "")[[1]])
#[1] 1 2 3 4 1 1 2 3 0 6 5 4 0 0 0 1