我有一个循环问题.它应该很容易解决,但"St for Stata用户"(我在Stata编码了几年),Roger Peng的视频和谷歌似乎没有帮助我.你们其中一个可以向我解释一下我做错了什么吗?
我正在尝试编写一个贯穿'thresholds'数据帧的循环来从三组列中提取信息.我可以通过三次编写相同的代码段来做我想做的事情,但随着代码变得越来越复杂,这将变得非常麻烦.
以下是"阈值"的示例(请参阅dput下面的输出,由友好的读者添加):
threshold_1_name threshold_1_dir threshold_1_value
1 overweight > 25
2 possible malnutrition < 31
3 Q1 > 998
4 Q1 > 998
5 Q1 > 998
6 Q1 > 998
threshold_1_units threshold_2_name threshold_2_dir threshold_2_value threshold_2_units
1 kg/m^2 obese > 30 kg/m^2
2 cm <NA> > NA
3 <NA> Q3 > 998
4 Q3 > 998
5 Q3 > 998
6 Q3 > 998
Run Code Online (Sandbox Code Playgroud)
这段代码做我想做的事:
newvars1 <- paste(thresholds$varname, thresholds$threshold_1_name, sep = "_")
noval <- is.na(thresholds$threshold_1_value) …Run Code Online (Sandbox Code Playgroud)