Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.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_Function_Vector_Tidyverse - Fatal编程技术网

R:传播向量的有效方法

R:传播向量的有效方法,r,function,vector,tidyverse,R,Function,Vector,Tidyverse,是否有一种有效的编程方法来解决以下任务 想象以下向量: A<-[a,b,c...k] ALet 一个选项是将rep与参数times=2或4一起使用,然后对结果进行排序。另一个选项是使用mapply,然后使用c操作符 c(mapply(rep, 2 ,A)) # OR sort(rep(A, times = 2)) #[1] "a" "a" "b" "b" "c" "c" "d" "d" "e" "e" "f" "f" "g" "g" "h" "h" "i" "i" "j" "j"

是否有一种有效的编程方法来解决以下任务

想象以下向量:

A<-[a,b,c...k]
ALet


一个选项是将
rep
与参数
times=2
4
一起使用,然后对结果进行
排序。另一个选项是使用
mapply
,然后使用
c
操作符

 c(mapply(rep, 2 ,A)) # OR sort(rep(A, times = 2))
 #[1] "a" "a" "b" "b" "c" "c" "d" "d" "e" "e" "f" "f" "g" "g" "h" "h" "i" "i" "j" "j"
 #[21] "k" "k"

 c(mapply(rep,A, 4))  #OR sort(rep(A, times = 2))
 #[1] "a" "a" "a" "a" "b" "b" "b" "b" "c" "c" "c" "c" "d" "d" "d" "d" "e" "e" "e" "e"
 #[21] "f" "f" "f" "f" "g" "g" "g" "g" "h" "h" "h" "h" "i" "i" "i" "i" "j" "j" "j" "j"
 #[41] "k" "k" "k" "k"
C<-[a,a,a,a,b,...,k,k,k,k]
A <- letters[1:11]
A
[1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k"
rep(A, each=2)
 [1] "a" "a" "b" "b" "c" "c" "d" "d" "e" "e" "f" "f" "g" "g" "h" "h" "i" "i" "j"
[20] "j" "k" "k"

rep(A, each=3)
[1] "a" "a" "a" "b" "b" "b" "c" "c" "c" "d" "d" "d" "e" "e" "e" "f" "f" "f" "g"
[20] "g" "g" "h" "h" "h" "i" "i" "i" "j" "j" "j" "k" "k" "k"
 c(mapply(rep, 2 ,A)) # OR sort(rep(A, times = 2))
 #[1] "a" "a" "b" "b" "c" "c" "d" "d" "e" "e" "f" "f" "g" "g" "h" "h" "i" "i" "j" "j"
 #[21] "k" "k"

 c(mapply(rep,A, 4))  #OR sort(rep(A, times = 2))
 #[1] "a" "a" "a" "a" "b" "b" "b" "b" "c" "c" "c" "c" "d" "d" "d" "d" "e" "e" "e" "e"
 #[21] "f" "f" "f" "f" "g" "g" "g" "g" "h" "h" "h" "h" "i" "i" "i" "i" "j" "j" "j" "j"
 #[41] "k" "k" "k" "k"