Dear R helpers

I have following dataset

rate_number = matrix(c(5, 15, 60, 15, 5, 0, 20, 60, 20,0, 10, 20, 40, 20, 10), 
nrow = 5, ncol = 3)

range_mat = matrix(c(6.25, 6.75, 7.25, 8.75, 9.25, 9.75, 8.5, 9, 9.5, 10.5, 11, 
11.5, 4.25, 4.75, 5.25, 5.75, 6.25, 6.75), nrow = 6, ncol = 3)

> rate_number
       [,1]   [,2]   [,3]
[1,]    5     0      10
[2,]   15   20      20
[3,]   60   60      40
[4,]   15   20      20
[5,]    5     0      10

> range_mat
     [,1]      [,2]     [,3]
[1,] 6.25     8.5   4.25
[2,] 6.75     9.0   4.75
[3,] 7.25     9.5   5.25
[4,] 8.75   10.5   5.75
[5,] 9.25   11.0   6.25
[6,] 9.75   11.5 6.75

My problem is to generate random numbers in line with rate_number and using the 
range_mat. E.g.

I need to generate (5, 15, 60, 15, 5 i.e. the first column of rate_number) 
uniform random numbers (using 1st column of range_mat) s.t the first 5 numbers 
will be in the range (6.25 - 6.75), next 15 numbers should be in the range 
(6.75 to 7.25), next 60 numbers should be in the range (7.25 to 8.75), next 15 
numbers in the range (8.75 to 9.25) and last 5 numbers in the range (9.25 to 
9.75).

Similarily, I need to generate (0, 20, 60, 20, 0 i.e. 2nd column of 
rate_number) uniform random numbers in the range (using 2nd column of 
range_mat) i.e. (8.5 to 9), (9 to 9.5), (9.5 to 10.5), (10.5 to 11), (11 to 
11.5) respectively.

I could have generated these random numbers Individually using runif, but main 
problem is range_number could be anything i.e. there may be 50 rates but for 
each rate, no of rate combination will always be 5 i.e. rate_number will always 
have 5 rows only and also range_mat will always have 6 rows only.

I tried writing loops and even tapply etc. but just can't get through.

I sincerely request you to kindly guide me.

Regards

Sarah  






      
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to