gpt4 book ai didi

r - 如何将随机种子分配给 dplyr sample_n 函数?

转载 作者:行者123 更新时间:2023-12-03 20:24:45 25 4
gpt4 key购买 nike

这是来自 R 中 dplyr 的“sample_n”。
https://dplyr.tidyverse.org/reference/sample.html
为了可重复性,我应该放置一个种子,以便其他人可以获得我的确切结果。
是否有内置的方法来设置“sample_n”的种子?
这是我在环境中做的事情并且“sample_n”响应它吗?
这些不是内置在“sample_n”函数中的。

  • 有环境“set.seed”功能[1]
  • 有一个库 'withr' 可以为代码 [2] 创建一个包含种子的包装器。

  • .

    最佳答案

    dplyr::sample_n documentation说:

    This is a wrapper around sample.int() to make it easy to select random rows from a table. It currently only works for local tbls.


    所以后面 sample_n , sample.int被调用,这意味着使用标准的随机数生成器,您可以使用 set.seed 为重现性。

    关于r - 如何将随机种子分配给 dplyr sample_n 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63441523/

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