, .
"" R sample(). , , .
, , , , - :
affils <- as.factor(c('democrat','republican','independent'))
counts <- c(552,431,27)
new.voters <- sample(affils,20, replace=TRUE,prob=counts)
new.counts <- table(new.voters)
In practice, you are likely to bring 100mm rows of values and counts using the R function read.csv (). Assuming you have a title bar that says “values \ t counts”, this code might look something like this:
dat <- read.csv('values-counts.txt',sep="\t",colClasses=c('factor','numeric'))
new.dat <- sample(dat$values,100,replace=TRUE,prob=dat$counts)
One caveat: as you know, R stores all its objects in memory, so make sure you have enough free access for 100-meter data rows (keeping character strings as factors will help reduce footprint).
source
share