
Dear R helpers
 
I am having following data
 
Name           Numbers
A                  25
B                   3  
C                  13
A                   5  
B                   7
C                   0
A                   2 
B                 10 
C                   9
 
CONDITIONS
 
If Name is A, min_val = 1.05, max_val = 1.30
If Name is B, min_val = 1.30, max_val = 1.60
If Name is C, min_val = 1.60, max_val = 1.99
 
TASK
 
To generate the Uniform random nos for each of these Names (Equal to the corresponding no. e.g. the 5th Name is B, so I need to generate 7 uniform random numbers in the range (1.30 - 1.99). Also I need to arrange these random numbers one by one in a single csv file i.e. say 25 random numbers in teh range (1.05-1.30) followed by 3 random numbers in the range (1.30-1.60) and so on.
 
# ___________________________________________________ 
 
Here is the R code I have tried
 
ONS <- read.table(textConnection("name number                  
A11    12                               
A12    17                               
A13     0                                   
A11    11                                
A12      6                                 
A13      0                                 
A11      8
A12      4                                 
A13      3"), header = TRUE)
 
X = as.character(ONS$name)
Y = ONS$number
 
Z = NULL
 
for (i in 1:length(X))
   {
   if(X[i] == 'A11')
   {
   min_val = 1.05
   max_val = 1.30
   Z = runif(Y[i], min_val, max_val)   
   }
   else
   {
   if(X[i] == 'A12')
   {
   min_val = 1.30
   max_val = 1.60
   Z = runif(Y[i], min_val, max_val)   
   }
   else
   {
   if(X[i] == 'A13')
   {
   min_val = 1.60
   max_val = 1.99
   Z = runif(Y[i], min_val, max_val)   
   }
   }
   }
   }
 
# End of Code
 
## _____________________________________________________________________
 
PROBLEM
 
I need to get 61 random numbers which is total of all the numbers (1st 12 fo A, 3 random numbers for B, 13 for C, 5 again fo A and so on). The result whcih I got is
 
> Z
[1] 1.740443 1.761758 1.797222
 
which is pertaining to the last name C where 3 random numbers are generated i.e. Z instaed of getting added, is overwritten.
 
Please help me to rectify my code so that in the end I will get 61 random numbers as desired i.e. 12 for A in the range (1.05 - 1.30), 3 for B in the range (1.30 - 1.60), 13 for C in the range (1.60-1.99), again 5 for A in the range (1.05 - 1.30).
 
Thanking in advance. I also sincerely apologize for writing such a long mail, as I wanted to be clear as possible in my communication.
 
Regards
 
Maithili
 
 


      The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. 
	[[alternative HTML version deleted]]


