text: Q:
  
  How can I subset in order?
  
  I created Beta Distribution B(1,3) with 500,000 random samples by by <- rbeta(500000, 1, 3), then I calculate sum(log(1-by)) but I want to calculate in group of 5 of by that mean I take first 5 samples of by and calculate sum(log(1-by)) of that first 5 samples, after that take the next 5 sample (5th to 10th samples) and calculte sum(log(1-by)), doing that till the end. Could you help me how to do that?
  
  A:
  
  Aggregate should do the job 
  aggregate(by ~ rep(1:100000, each = 5), FUN = function(x) sum(log(1-x)))
  
  This does log(1-by) for each element of by then sums those for 1st to 5th, 6th to 10th etc. as seen here
  > V1 <- rbeta(6, 1, 3)
  > log(1-V1)
  [1] -1.03779783 -0.04631726 -0.02731994 -0.99583209 -0.03959935 -0.02131620
  > aggregate(V1 ~ rep(1:2, each = 3), FUN = function(x) sum(log(1-x)))
    rep(1:2, each = 3)        V1
  1                  1 -1.111435
  2                  2 -1.056748
  
  To extract that column of summed values as a vector just add [,2] after to make aggregate(...)[,2].
  
  