# Werden wir Helden für einen Tag

Home | About | Archive

# How to rewrite ugly R code #1

Posted on Apr 11, 2011 by Chung-hong Chan

# < - crew it.
bmisds <- function (age, gender, bmi){
if (age ==1 && gender =="F")
{
bmif <- c(-1.013,16.133,0.07656)
}
else if (age ==1 && gender == "M")
{
bmif <- c(-1.79,16.421,0.07149)
}
else if (age == 2 && gender == "F")
{
bmif <- c(-1.403,15.58,0.07342)
}
else if (age == 2 && gender == "M")
{
bmif <- c(-2.045,15.861,0.07116)
}
else if (age == 3 && gender == "F")
{
bmif <- c(-1.612,15.39,0.0741)
}
else if (age == 3 && gender == "M")
{
bmif <- c(-2.2, 15.59,0.0729)
}
else if (age == 4 && gender == "F")
{
bmif <- c(-1.735, 15.097, 0.07983)
}
else if (age ==4 && gender == "M")
{
bmif <- c(-2.287, 15.276,0.07908)
}
else if (age == 5 && gender == "F")
{
bmif <- c(-1.808, 14.84, 0.08897)
}
else if (age == 5 && gender == "M")
{
bmif <- c(-2.328,15.072,0.08867)
}
else if (age == 6 && gender == "F")
{
bmif <- c(-1.851, 14.747,0.09948)
}
else if (age == 6 && gender == "M")
{
bmif <- c(-2.337,15.026,0.09985)
}
else if (age == 7 && gender == "F")
{
bmif <- c(-1.874, 14.839, 0.10956)
}
else if (age == 7 && gender == "M")
{
bmif <- c(-2.323, 15.149, 0.11077)
}
else if (age == 8 && gender == "F")
{
bmif <- c(-1.882, 15.101, 0.11817)
}
else if (age == 8 && gender == "M")
{
bmif <- c(-2.296, 15.423, 0.12036)
}
else if (age == 9 && gender == "F")
{
bmif <- c(-1.88, 15.497, 0.12486)
}
else if (age == 9 && gender == "M")
{
bmif <- c(-2.26, 15.798, 0.12825)
}
else if (age == 10 && gender == "F")
{
bmif <- c(-1.872, 15.993, 0.1296)
}
else if (age == 10 && gender == "M")
{
bmif <- c(-2.221, 16.232, 0.13443)
}
else if (age == 11 && gender == "F")
{
bmif <- c(-1.86, 16.557, 0.13274)
}
else if (age == 11 && gender == "M")
{
bmif <- c(-2.18, 16.702,0.13902)
}
else if (age == 12 && gender == "F")
{
bmif <- c(-1.848,17.155,0.1345)
}
else if (age == 12 && gender == "M")
{
bmif <- c(-2.139,17.193,0.1423)
}
else if (age == 13 && gender == "F")
{
bmif <- c(-1.835,17.757,0.13528)
}
else if (age == 13 && gender == "M")
{
bmif <- c(-2.101,17.697,0.14458)
}
else if (age == 14 && gender == "F")
{
bmif <- c(-1.822,18.338,0.13544)
}
else if (age == 14 && gender == "M")
{
bmif <- c(-2.064,18.205,0.14617)
}
else if (age == 15 && gender == "F")
{
bmif <- c(-1.809,18.884,0.13527)
}
else if (age == 15 && gender == "M")
{
bmif <- c(-2.03,18.704,0.14733)
}
else if (age >= 16 && gender == "F")
{
bmif < - c(-1.1797,19.393,0.13497)
}
else if (age >= 16 && gender == "M")
{
bmif < - c(-1.997,19.186,0.14826)
}
(((bmi/bmif[2])**bmif[1] -1)/(bmif[1]*bmif[3]))
}


z = (x - mean) / sd

Powered by Jekyll and profdr theme, a fork of true minimal theme