gpt4 book ai didi

从 R 中的序列中随机提取多个连续项目

转载 作者:行者123 更新时间:2023-12-04 00:40:05 24 4
gpt4 key购买 nike

Frag <- seq(1: 30000)
K <- 9
P <- sample(1:K,1)
sys.sample <- Frag[seq(P, length(Frag), K)]

现在 sys.sample 包含 3333 个数字。如何在 R 中随机抽取 16 个连续项?

最佳答案

如果一个向量 vn元素,你想随机提取 p连续元素( p<=n ),你可以这样做:

possibleIndex = seq(length(v) - p + 1)
firstIndex = sample(possibleIndex, 1)

v[firstIndex:(firstIndex + p -1)]

关于从 R 中的序列中随机提取多个连续项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32945338/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com