如何在R中创建一个随机的月份样本?

可以使用样本函数创建随机样本,并可以借助month.name函数生成一年中的月份。因此,如果我们要创建一个随机的月份样本,则可以使用month.name并将样本函数用作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]“ 6月”“ 9月”“ 7月”“ 6月”“ 10月”“ 11月” [7]“ 2月”“ 8月”“ 3月”“ 4月”“ 7月”“ 8月” [13]“ 10月”“ 4月“” 6月“” 4月“” 3月“” 4月“ [19]” 11月“” 9月“” 1月“” 8月“” 6月“” 3月“ [25]” 9月“” 10月“” 7月“” 10月“”三月“”八月“ [31]”十二月“”二月“”十月“”七月“”四月“”十二月“ [37]”十一月“”三月“”五月“”九月“”五月“”十二月“ [43] “游行”“ 9月”“ 1月”“ 8月”“ 10月”“ 4月” [49]“ 6月”“ 9月”

示例

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"