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

R 将常量和所有较低的自然数附加到列表中的数字

R 将常量和所有较低的自然数附加到列表中的数字,r,list,append,R,List,Append,是否有一种简单的方法可以将所有数字(1:常量)添加到列表中,如下面的示例所示,而不必手动键入(或使用for循环) >列表常量唯一(c(列表,列表+1,列表+2,列表+3)) [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 我希望能够分配一个常量,并将常量和所有较低的自然数附加到列表中的数字 谢谢 编辑: 以下是我试图做的,除了没有for循环: > list <- c(1:10) > list2 <- c(1:10) > con

是否有一种简单的方法可以将所有数字(1:常量)添加到列表中,如下面的示例所示,而不必手动键入(或使用for循环)

>列表常量唯一(c(列表,列表+1,列表+2,列表+3))
[1]  1  2  3  4  5  6  7  8  9 10 11 12 13
我希望能够分配一个常量,并将常量和所有较低的自然数附加到列表中的数字

谢谢

编辑:

以下是我试图做的,除了没有for循环:

> list <- c(1:10)
> list2 <- c(1:10)
> constant <- 3
> for(i in 1:constant){
+ list2<-unique(c(list2,list+i))
+ }
> list2
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 
v <- 1:10  ## better not to call this "list"
constant <- 3
unique(c(outer(0:constant,v,"+")))
>列出列表2常量(1中的i:常量){
+列表2列表2
[1]  1  2  3  4  5  6  7  8  9 10 11 12 13 

这不是非常有效,但比for循环更好:

> list <- c(1:10)
> list2 <- c(1:10)
> constant <- 3
> for(i in 1:constant){
+ list2<-unique(c(list2,list+i))
+ }
> list2
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 
v <- 1:10  ## better not to call this "list"
constant <- 3
unique(c(outer(0:constant,v,"+")))

v谢谢!非常适合我的需要。