I need to select random rows from different numeric intervals I´ve stipulated. The following topic is very related, but in this case the rows were selected from levels:
selecting n random rows across all levels of a factor within a dataframe
Using the same sample example:
df <- data.frame(matrix(rnorm(80), nrow=40))
df$color <- rep(c("blue", "red", "yellow", "pink"), each=10)'
How could I select 4 rows (or any other n) from where -1< X1<0 and 4 rows where 0 ≤ X1<2?