Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.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中生成seq块_R - Fatal编程技术网

在R中生成seq块

在R中生成seq块,r,R,如何在R中生成类似的序列而不使用循环?例如,[1,2,3,4,5,8,9,10,11,12,15,16,17,18,19]等等。这可以解释为:如果索引是平日,我只想选择“不周末”(或“周末”)。假设您希望数字持续到50。使用载体回收的一种方法可以是: n <- 1:50 n[rep(c(TRUE, FALSE), c(5, 2))] #[1] 1 2 3 4 5 8 9 10 11 12 15 16 17 18 19 22 23 24 25 26 29 #[22] 30 3

如何在R中生成类似的序列而不使用循环?例如,[1,2,3,4,5,8,9,10,11,12,15,16,17,18,19]等等。这可以解释为:如果索引是平日,我只想选择“不周末”(或“周末”)。

假设您希望数字持续到50。使用载体回收的一种方法可以是:

n <- 1:50
n[rep(c(TRUE, FALSE), c(5, 2))]

#[1]  1  2  3  4  5  8  9 10 11 12 15 16 17 18 19 22 23 24 25 26 29
#[22] 30 31 32 33 36 37 38 39 40 43 44 45 46 47 50
n[n %% 7 %in% 1:5]