r generate random poisson values

Ahir Bhairav Orai

How do I randomly generate 50% 1s, 30% 2s, 15% 3s and remaining 4s ?

Finally when I do a table , table(x, useNA = "ifany"), it should be

                         1      2      3    4
                         50     30     15   5

I am not sure how to use rpois to generate this.

jay.sf

Using sample.int.

set.seed(42)
x <- sample.int(n=4, size=1e4, replace=TRUE, prob=c(.5, .3, .15, 1 - sum(c(.5, .3, .15))))

proportions(table(x))
# x
#      1      2      3      4 
# 0.5001 0.3001 0.1506 0.0492 

If you depend on rpois, you probably need to invent something with optimize.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Algorithm to generate Poisson and binomial random numbers?

How do I generate discrete random events with a Poisson distribution?

JavaScript generate random number except some values

Generate random values given a PDF

When does SQLite RANDOM() generate values?

Weird output of poisson GLM with an iid random effect in r

Javascript Using Math.random to generate random rgba values in for loop

Generate a matrix without 0 values in a random way

Generate random numbers for groups R

generate random vector in R based on values of other vectors, probability

Generate random doubles in between a range of values - Java

Generate random values in oracle view

R Using distributions to generate random variables, but with many different dimensions and parameter values

Random generate three integer values and check if they are unique

generate poisson distribution using R

Generate random values in R with a defined correlation in a defined range

Generate random values based on a seed Swift 3

How to generate random values from a string in python?

MatLab:Generate N pseudo-random numbers with a Poisson distribution having mean M and total T where N,M, and T are user defined

Generate random values from boxplot

How to generate N random values with SELECT?

How to generate random values for a predefined function?

Generate new random values and store in an array

How can we generate random values in Scrypto?

Poisson random variable in python

Generate Valid Random Faker Values in Go

Generate values in R and Python

R Shiny: actionButton to generate random value from input values and render plot

How to generate a matrix of random values with zeros on the diagonal?