mat*_*tty -2 random r dataframe
在不从数据帧替换的情况下获取随机样本。我将该样本分配给一个新的数据框。我想使用该示例中剩余的行。
为了创建示例,我使用了:
telemarketing_sample <- telemarketing[sample(1:nrow(telemarketing), 30000, replace=FALSE),]
Run Code Online (Sandbox Code Playgroud)
通常,提供一些您已经尝试过给人们以入门的代码会很有帮助。同时,这样的事情应该起作用:
#generate some toy data
x <- data.frame(id = 1:100, y = rep(c(0,1),50))
#get a sample of 10
samp <- sample(nrow(x),10)
#data in the sample
in <- x[samp,]
#data not in the sample
out <- x[-samp,]
Run Code Online (Sandbox Code Playgroud)