r - Function for thresholds of two variables -


i trying write function 2 variables. m has 4 categories: equal 19 or less,20,21, , 22. al has 3 categories: less 30,30 400, , over 400.

input: m=c(19,20,21,22) al=c(30,400)  output: out1 <- c(0.95, 0.94. 0.93, 0.92) out21 <- 1.091+3.02*(al-30) out22 <- 1.093+3.03*(al-30) out23<-  1.099+3.08*(al-30) out24 <- 1  out3 <- c(0.87, 0.89, 0.91, 0.93) 

i trying write function if else looks like

out <- function(m,al) {  if(m<=19 & al<30){   out=0.95      } else {   if(m=20 & al<30){     out=0.94       } else {     if(m=21 & al<30){       out=0.93     ... 

i easy looking function gives me output more easily. further explanation on conditions:

if m <=19 & al <30, out=0.95 if m =20 & al <30, out=0.94  ...  if m <=19 & al in between 30 , 400, out=1.091+3.02*(al-30) if m =20 & al in between 30 , 400, out=1.093+3.03*(al-30) ...  if m <=19 & al >400, out=0.87 if m =20 & al >400, out=0.89 


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -