全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
1831 3
2014-04-02

ind<-sample(2,nrow(iris),replace=TRUE,prob=c(0.7,0.3)

哪位同学给具体解释一下上面的话,我只知道iris 是数据,其他都不是很不明白,谢谢
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2014-4-2 22:34:42
随机变量X服从两点分布:P(X=1)=0.7,P(X=2)=0.3,上述命令就是产生nrow(iris)个X的随机数。
nrow(iris)是数据的行数。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-4-3 02:13:47
有时候,一个"?sample" 比到论坛上找解释还要快:
Random Samples and Permutations

Description

sample takes a sample of the specified size from the elements of x using either with or without replacement.

Usage

sample(x, size, replace = FALSE, prob = NULL)

sample.int(n, size = n, replace = FALSE, prob = NULL)
Arguments

x       
Either a vector of one or more elements from which to choose, or a positive integer. See ‘Details.’

n       
a positive number, the number of items to choose from. See ‘Details.’

size       
a non-negative integer giving the number of items to choose.

replace       
Should sampling be with replacement?

prob       
A vector of probability weights for obtaining the elements of the vector being sampled.

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-4-3 13:33:06
太好了, 谢谢楼上2位好心童鞋!!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群