-6

I have the following table:

#Rainfall(PCP-minimum)        #Rainfall(PCP-maximum)        #Rainfall_index(DRI) 

0               -              4.9                           0
5                -             9.9                           1
10              -             14.9                           2

So the general formula is:

5*n              -            5*n+4.9                       n

I would like to code such table using R to get the variable DRI

So if PCP is between 0-4.9 then DRI= 0 and if PCP between 5-9.9 then DRI = 1 and so on so the general rule that If PCP between 5n- 5n+4.9 then DRI = n

Thanks in Advance

  • No it is a different question I have a variable that is an interval I want to create an index variable DRI for each category so the first category takes 0 the second takes 1 and so on up to n – Marwah M Soliman Jul 29 '13 at 02:39
  • Could you explain with more details the part you talk about the normal distribution? – Andre Silva Jul 29 '13 at 02:49
  • Ok assume that I have a Normal distribution data that can be put in the table above the MAx and Min values now I want to create an index DRI that gives 0 for the first category and 1 for the second category and so on my question is how to put the above data in such format and how to get the index variable? – Marwah M Soliman Jul 29 '13 at 02:54
  • So if PCP is between 0-4.9 then DRI= 0 and if PCP between 5-9.9 then DRI = 1 and so on so the general rule that If PCP between 5n- 5n+4.9 then DRI = n – Marwah M Soliman Jul 29 '13 at 03:05

1 Answers1

2

Do you just want to code the table up? Would something like this suffice?:

PCP <- c(0, 4.9, 5, 9.9, 10, 14.9, 15)
seq2max <- seq(0,max(PCP)+5,5)

result <- data.frame(min=seq2max,max=seq2max+4.9,DRI=seq_along(seq2max)-1)

  min  max DRI
1   0  4.9   0
2   5  9.9   1
3  10 14.9   2
4  15 19.9   3
5  20 24.9   4

result$DRI
# [1] 0 1 2 3 4
thelatemail
  • 91,185
  • 12
  • 128
  • 188