如何在R语言中创建月份的随机样本?


可以使用 `sample` 函数创建随机样本,并可以使用 `month.name` 函数生成一年中的月份。因此,如果要创建月份的随机样本,则可以将 `month.name` 与 `sample` 函数一起使用,例如 `sample(month.name)`。如果样本大小大于12,则应使用 `replace=TRUE` 参数。

示例

 在线演示

x1<−sample(month.name)
x1

输出

[1] "October" "April" "March" "May" "June" "December"
[7] "July" "September" "January" "February" "November" "August"

示例

 在线演示

x2<−sample(month.name,20,replace=TRUE)
x2

输出

[1] "August" "May" "June" "May" "October" "October"
[7] "February" "October" "March" "May" "October" "November"
[13] "December" "November" "August" "May" "July" "January"
[19] "July" "June"

示例

 在线演示

x3<−sample(month.name,30,replace=TRUE)
x3

输出

[1] "April" "April" "November" "January" "September" "October"
[7] "June" "July" "March" "May" "December" "October"
[13] "December" "September" "August" "June" "November" "March"
[19] "November" "January" "May" "August" "February" "September"
[25] "July" "July" "February" "July" "November" "September"

示例

 在线演示

x4<−sample(month.name,50,replace=TRUE)
x4

输出

[1] "六月" "九月" "七月" "六月" "十月" "十一月" [7] "二月" "八月" "三月" "四月" "七月" "八月" [13] "十月" "四月" "六月" "四月" "三月" "四月" [19] "十一月" "九月" "一月" "八月" "六月" "三月" [25] "九月" "十月" "七月" "十月" "三月" "八月" [31] "十二月" "二月" "十月" "七月" "四月" "十二月" [37] "十一月" "三月" "五月" "九月" "五月" "十二月" [43] "三月" "九月" "一月" "八月" "十月" "四月" [49] "六月" "九月"

示例

 在线演示

x5<−sample(month.name,60,replace=TRUE)
x5

输出

[1] "December" "June" "May" "February" "February" "January"
[7] "January" "November" "March" "March" "July" "October"
[13] "February" "July" "November" "February" "October" "March"
[19] "September" "June" "April" "April" "November" "February"
[25] "May" "February" "March" "April" "September" "October"
[31] "November" "November" "April" "July" "June" "September"
[37] "December" "May" "August" "April" "October" "August"
[43] "November" "September" "February" "March" "July" "December"
[49] "March" "September" "December" "May" "November" "January"
[55] "March" "November" "May" "October" "February" "March"

示例

 在线演示

x6<−sample(month.name,61,replace=TRUE)
x6

输出

[1] "February" "June" "March" "March" "August" "November"
[7] "November" "March" "December" "September" "November" "January"
[13] "June" "February" "February" "July" "July" "June"
[19] "July" "March" "September" "July" "November" "October"
[25] "February" "October" "February" "January" "April" "November"
[31] "September" "August" "October" "July" "May" "November"
[37] "March" "April" "July" "February" "September" "July"
[43] "March" "January" "November" "August" "January" "September"
[49] "April" "September" "December" "March" "July" "January"
[55] "February" "March" "August" "December" "October" "June"
[61] "June"

示例

 在线演示

x7<−sample(month.name,90,replace=TRUE)
x7

输出

[1] "January" "June" "February" "November" "April" "February"
[7] "December" "November" "July" "July" "October" "May"
[13] "November" "May" "September" "June" "November" "December"
[19] "February" "July" "March" "June" "March" "March"
[25] "December" "June" "May" "November" "October" "May"
[31] "May" "November" "August" "November" "September" "May"
[37] "May" "April" "February" "September" "July" "March"
[43] "September" "March" "January" "September" "December" "October"
[49] "December" "April" "February" "April" "January" "December"
[55] "September" "February" "September" "October" "December" "April"
[61] "June" "March" "October" "September" "October" "January"
[67] "July" "September" "March" "February" "May" "August"
[73] "April" "August" "January" "December" "September" "October"
[79] "March" "January" "May" "August" "February" "July"
[85] "February" "February" "December" "July" "March" "December"

示例

 在线演示

x8<−sample(month.name,92,replace=TRUE)
x8

输出

[1] "February" "December" "October" "July" "June" "November"
[7] "July" "October" "December" "March" "April" "July"
[13] "April" "February" "January" "July" "June" "February"
[19] "January" "October" "February" "November" "September" "October"
[25] "March" "September" "November" "September" "June" "November"
[31] "July" "April" "February" "February" "March" "November"
[37] "September" "December" "April" "April" "March" "February"
[43] "July" "February" "November" "August" "July" "October"
[49] "April" "February" "June" "July" "March" "August"
[55] "March" "December" "May" "November" "November" "February"
[61] "November" "October" "September" "July" "July" "May"
[67] "January" "December" "April" "January" "November" "May"
[73] "October" "September" "December" "June" "January" "December"
[79] "March" "February" "December" "December" "February" "December"
[85] "October" "July" "June" "January" "October" "June"
[91] "August" "October"

更新于: 2020年11月6日

328 次浏览

启动你的职业生涯

完成课程获得认证

开始学习
广告