Obtaining random number from a mixture of two normal distributions I want to sample from mixed normal distribution, first one is $N(1,2)$, second one is $N(5,4)$. I used rnorm(100, c(mean=c(1,5), sd=c(2,4))). Is this correct?
The problem I am trying to solve is sampling from the 2 distribution above, first one with 75%, second one with 25%.  Am I on the right track?
Edit:  I will rewrite the problem for clearance, with easier numbers. :)
I want to sample from $N(0,1)$ with 70% probability, and $N(100,10)$ with 30% probability.
Of course, that's just for sake of discussion, the actually distribution I am working with is n(21, 3.3), n(26,4).
 A: If you want to sample unequally (with probability 0.7 and 0.3) from two gaussians with parameters $(\mu_1,\sigma_1^2)$ and $(\mu_2,\sigma_2^2)$, then you can probably try something like that:
n <- 100
yn <- rbinom(n, 1, .7)
# draw n units from a mixture of N(0,1) and N(100,3^2)
s <- rnorm(n, 0 + 100*yn, 1 + 2*yn)

In fact, this is one of the illustrations provided in Modern Applied Statistics with S, by Venables and Ripley (Springer, 2002; §5.2, pp. 110-111).
With different parameters, you can use an ifelse expression to select the mean and SD according to the binomial sequence given in yn, e.g. rnorm(n, mean=ifelse(yn, 21, 26), sd=ifelse(yn, 3.3, 4)). (No need to cast yn to a logical with as.logical.)
A: To accomplish the goal of sampling from an uneven mixture of distributions, the most straightforward approach is to sample separately, in proportion to the desired ratio:
 p <- 0.70 #P(from N(mu1, sd1)) 
 n.samps <- 10000
 mu1 <- 0
 sd1 <- 1
 mu2 <- 100
 sd2 <- 10

 x <- vector()
 for(i in 1:n.samps){
    b <- runif(1, 0, 1)
    if(b < p){
       x[i] <- rnorm(1, mu1, sd1)
     } else { 
       x[i] <- rnorm(1, mu2, sd2)
     }
   }

this can be done ~50 x faster:
 binary <- runif(n.samps, 0, 1) > p
 x <- c(rnorm(sum(binary), 1, 2), rnorm(sum(!binary), 5, 4)

then to draw a sample:
sample(x, 1)

or to reshuffle: 
x <- sample(x, n.samp)

