twitterpig
V2EX  ›  问与答

R 语言包 ggplot2 中 set.seed 参数的疑问?

  •  
  •   twitterpig · May 25, 2017 · 2515 views
    This topic created in 3313 days ago, the information mentioned may be changed or developed.

    #load the ggplot2 library

    library(ggplot2)

    #set the seed so we can reproduce the results ##让样本可重复

    set.seed(1410)

    #create a variable that is the first 100 rows of the diamonds dataset

    dsmall <- diamonds[sample(nrow(diamonds), 100), ]

    set.seed 中的 1410,取这个数字有特殊的意义吗?是不是也可以取个随机数?

    我在网络上搜索到一些解释:

    1.设置随机数种子。

    2.就是设定随机数,保证下次生成的随机数和前面的一样

    小白不是特别明白,求教。谢谢

    marenight
        1
    marenight  
       May 25, 2017 via iPhone   ❤️ 1
    数字随便取,不过要想取得一致的随机结果,种子需要一样
    srlp
        2
    srlp  
       May 25, 2017
    随便。不 set.seed 也可以
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2559 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 08:05 · PVG 16:05 · LAX 01:05 · JFK 04:05
    ♥ Do have faith in what you're doing.