1、随机抽样



> a <- 1:10
> sample(a,5)
[1] 9 4 5 10 6
> sample(a,5,replace = T)
[1] 10 7 5 3 4
> sample(a,5,replace = T) ## 有放回抽样
[1] 5 9 5 1 3


 



> b <- LETTERS[1:10]
> b
[1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
> sample(b,5)
[1] "F" "D" "J" "G" "A"
> sample(b,5)
[1] "G" "I" "H" "E" "D"
> sample(b,5,replace = T)
[1] "F" "G" "C" "I" "H"
> sample(b,5,replace = T)
[1] "I" "G" "G" "I" "A"


 

2、随机抽一万行



> data <- read.table("outcome.map")
> dim(data)
[1] 46827 4
> data2 <- data[sample(1:nrow(data), 10000),]
> dim(data2)
[1] 10000 4