I would like to create a logical vector that has 10 rows, with each row randomly assigned either TRUE or FALSE. However, I want there to only be 3 FALSE and 7 TRUE.
Example of desired outcome (logical vector with three randomly assigned FALSE entries and 7 randomly assigned TRUE entries):
> vector
[1] "TRUE" "TRUE" "FALSE" "TRUE" "FALSE" "FALSE" "TRUE" "TRUE" "TRUE"
[10] "TRUE"
I can create a logical vector of size 10 that has TRUE or FALSE, but I don't know how to specify I want three FALSE entries and 7 TRUE entries.
vector <- sample(x = c("TRUE","FALSE"), size = 10, replace = TRUE)
This produces:
> train
[1] "TRUE" "TRUE" "FALSE" "TRUE" "FALSE" "FALSE" "FALSE" "FALSE" "FALSE"
[10] "TRUE"
Which has the incorrect number of TRUE and FALSE entries (4 TRUE and 6 FALSE).
sample( c( rep(TRUE,7), rep(FALSE,3) ) )
? - Wimpel