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

R 基于值拆分向量或列表

R 基于值拆分向量或列表,r,R,我正在尝试拆分以下列表: x <- c(1, 19, 25, 62, 38, 41, 52, 53, 60, 61, 1, 74, 72, 66, 1, 68, 5, 1) x使用split和cumsum: x <- c(1, 19, 25, 62, 38, 41, 52, 53, 60, 61, 1, 74, 72, 66, 1, 68, 5, 1) split(x, f=cumsum(x==1)) #> $`1` #> [1] 1 19 25 62 38

我正在尝试拆分以下列表:

x <- c(1, 19, 25, 62, 38, 41, 52, 53, 60, 61,  1, 74, 72, 66, 1, 68, 5, 1)

x使用
split
cumsum

x <- c(1, 19, 25, 62, 38, 41, 52, 53, 60, 61,  1, 74, 72, 66, 1, 68, 5, 1)

split(x, f=cumsum(x==1))

#> $`1`
#> [1]  1 19 25 62 38 41 52 53 60 61
#> 
#> $`2`
#> [1]  1 74 72 66
#> 
#> $`3`
#> [1]  1 68  5
#> 
#> $`4`
#> [1] 1
x$`1`
#> [1]  1 19 25 62 38 41 52 53 60 61
#> 
#> $`2`
#> [1]  1 74 72 66
#> 
#> $`3`
#> [1]  1 68  5
#> 
#> $`4`
#> [1] 1

这是针对R语言的吗?或者另一种语言,特别是rstudio.rstudio不是一种语言,而是一种IDE(即一种非常奇特和有用的文本编辑器)
x <- c(1, 19, 25, 62, 38, 41, 52, 53, 60, 61,  1, 74, 72, 66, 1, 68, 5, 1)

split(x, f=cumsum(x==1))

#> $`1`
#> [1]  1 19 25 62 38 41 52 53 60 61
#> 
#> $`2`
#> [1]  1 74 72 66
#> 
#> $`3`
#> [1]  1 68  5
#> 
#> $`4`
#> [1] 1