【发布时间】:2018-08-04 11:55:40
【问题描述】:
我的数据是这种格式,尤其是性别和种族是因素。
>head(scr)
age scr sex ethnic
1 48 1.2 Female Other
2 7 0.8 Male Black
3 62 1.8 Female <NA>
4 48 3.8 Female Other
5 51 1.4 Male Other
函数主要是计算方程: enter image description here 但是当我输入数据时,它显示性别和种族参数缺失,没有默认值。
egfr.mdrd4(scr[1,])
那么,如何改变性别和种族的函数或数据类型来运行这个函数呢?
egfr.mdrd4 <- function(scr, age, sex, ethnic){
if (sex == "Female")
n<-0.742
else
n<-1
if (ethnic == "Black")
m<-1.212
else
m<-1
mdrd<-175*scr^(-1.154)*age^(-0.203)*n*m
return (mdrd)
}
egfr.md(scr[1,])
【问题讨论】:
-
试试
if (as.character(sex) == "Female")和ethnic一样。 -
您也可以将
sex和ethnic转换为字符:例如:scr$sex <- as.character(scr$sex) -
谢谢你的帮助,这个方法我已经试过了。
标签: r function debugging arguments