Skip to content
Prev 106748 / 398506 Next

Error: cannot take a sample larger than the population

Hi,
In Splus7 this statement
xlrmN1 <- sample(c(0,1,2),400 ,prob=c(0.02 ,0.93 ,0.05 ))
worked fine, but in R the interpreter reports that the length of the 
vector to chose c(0,1,2) is shorter than the size of many times I want 
to be selected from the vector c(0,1,2).
Any good reason?
See below the error.

 > xlrmN1 <- sample(c(0,1,2),400 ,prob=c(0.02 ,0.93 ,0.05 ))
Error in sample(length(x), size, replace, prob) :
        cannot take a sample larger than the population
 when 'replace = FALSE'
Execution halted

TIA,

Aldi

--