Reputation: 69
I am attempting to use R to simulate transaction amounts from a transactional database, specifically in the range $500<=x<$1000
. Over time, the values in this range have had the following frequencies (I show the top 17 only). Is there any simple way to simulate an random dataset given a list of frequencies like the following? Thanks much in advance!
Amount Frequency
500 52%
600 8%
750 3%
700 3%
800 2%
900 2%
550 2%
850 1%
650 1%
525 1%
510 1%
675 1%
625 1%
757 1%
680 1%
950 1%
Upvotes: 2
Views: 60
Reputation: 21057
Use sample
:
# I modified your example for the sum of frequencies to be 1
df <- data.frame(
amount = c(500,600,750,700,800,900,550,850,650,525,510,675,625,757,680,950),
frequency = c(52,18,6,6,5,2,2,1,1,1,1,1,1,1,1,1) / 100
)
sample(df$amount, size=5, replace=T, prob=df$frequency)
## [1] 500 525 500 500 800
Upvotes: 2