gpt4 book ai didi

r - 使用样本空间大小为 1 的 sample()

转载 作者:行者123 更新时间:2023-12-04 09:55:48 26 4
gpt4 key购买 nike

我有一个我希望从中采样的日期列表。有时样本空间只是一个日期,例如样本(“10/11/11”,1)。日期存储为 chron 对象,因此当我的样本空间中只有一个日期时(并且只有那时)样本将其视为向量(1:日期)。 sample 的文档指出了这一点:

 If ‘x’ has length 1, is numeric (in the sense of ‘is.numeric’) and
‘x >= 1’, sampling _via_ ‘sample’ takes place from ‘1:x’. _Note_
that this convenience feature may lead to undesired behaviour when
‘x’ is of varying length in calls such as ‘sample(x)’. See the
examples.

但是我没有看到禁用此功能的方法。是否有解决方法或方法可以阻止它将长度为 1 的对象视为数字?

最佳答案

sample文档建议这样做:

resample <- function(x, ...) x[sample.int(length(x), ...)]

关于r - 使用样本空间大小为 1 的 sample(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7547758/

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