jeudi 26 octobre 2017

creating a vector of randomly generated numbers based on a previous randomly generated string

I have a set of code that creates a dummy variable matrix of size 3xn. This gives the following combinations- 111 110 101 100 011 010 001 000

    variable1 <- sample (0:1, 1000, replace = T, prob = c(.5,.5))
    variable2 <- sample(0:1, 1000, replace = T, prob = c(.5,.5))
    variable3 <- sample(0:1, 1000, replace = T, prob = c(.5,.5))
    data <- data.frame(cbind(variable1 , variable2 , variable3 ))
    View (data)

What I would like to do is to populate a number of additional columns based off of the randomly generated dummy variables. Particularly I want to create simulated data based off various normal distributions where the mean and standard deviation are different for each dummy code.

e.g. for a new column vector, the code 111 might sample from a distribution of mean 10 and sd 1 while the code 000 would sample from one with mean 5 and sd 2.

I am just having a little trouble.




Aucun commentaire:

Enregistrer un commentaire