0

I have data in a form much like the output from aggregate, except that I do not have the original non-aggregated data.

Example:

 data <- data.frame(grade=letters[1:4], count=c(3,9,4,1))
  grade count
1     a     3
2     b     9
3     c     4
4     d     1

I would like to sample from this population of grades, e.g. using sample. What is the easiest way of taking a sample (without replacement) from summarized counts like this?

MattLBeck
  • 5,701
  • 7
  • 40
  • 56

1 Answers1

4

Do you expect something like this?

> sample(with(data, rep(as.character(grade), count)), 10)
 [1] "b" "b" "d" "a" "c" "c" "b" "b" "c" "b"
Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138