【发布时间】:2021-08-20 07:52:57
【问题描述】:
考虑 R 中的可重现示例:
test <- c(1:12)
> test
[1] 1 2 3 4 5 6 7 8 9 10 11 12
预期结果:
test.list <- split(test, gl(2, 3))
> test.list
$`1`
[1] 1 2 3 7 8 9
$`2`
[1] 4 5 6 10 11 12
我正在尝试用 C++ 编写等效代码,以生成并返回由 test.list 生成的两个向量。请注意,我在 C++ 中处于尴尬的新手阶段。
【问题讨论】:
-
你试过什么?你在哪里卡住了?请出示minimal reproducible example
-
我实际上是在尝试理解我发现的 C++ 中的一个类似代码块 (techiedelight.com/split-vector-into-subvectors-cpp),并试图弄清楚我是否可以升级它以满足我的要求。除此之外,我没有 C++ 的可重现示例。