I am trying to write a function with two variables. m
has four categories: equal to 19 or less
,20
,21
, and 22
. al
has three categories: less than 30
,30 to 400
, and 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 am trying to write a function with if
else
that 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 like to get an easy looking function that gives me output more easily. Further explanation on the conditions:
If m <=19 & al <30, out=0.95
If m =20 & al <30, out=0.94
...
If m <=19 & al in between 30 and 400, out=1.091+3.02*(al-30)
If m =20 & al in between 30 and 400, out=1.093+3.03*(al-30)
...
If m <=19 & al >400, out=0.87
If m =20 & al >400, out=0.89
Aucun commentaire:
Enregistrer un commentaire