0
所以我想循环一些数据并在我的代码中使用它们。在这里我需要这个东西试试看的位置是在以下几点:如何在R中使用try语句?
for (number in numbers) {
CTV_volume <- CTV[ which(CTV$Key==number), ]$volume
PTV_volume <- PTV[ which(PTV$Key==number), ]$volume
ITV_volume <- ITV[ which(ITV$Key==numbers), ]$volume
large_volume <- large_margin_vol_calc(radius_calc(CTV_volume), a_large, b_large)
small_volume <- small_margin_vol_calc(radius_calc(CTV_volume), a_small, b_small)
}
的事情是CTV_volume
计算在最后两行(large_volume
和small_volume
)取决于数据从第一线以上(CTV_volume
)。但是,对于循环的每一次迭代,都有可能没有该特定键/数字的CTV,而是需要使用另一个,即ITV。但首先我需要它首先使用CTV,如果不存在的话,那么ITV词。
这是如何在R中完成的?
这很容易。尝试“如果”。此外,由于你循环,你需要将你的值保存在列表或向量中。 – Alice
但是我可以使用if语句有错误吗?例如,当我运行代码并运行到CTV不存在的地方时,我会得到“value”数值(0)而不是数字。人们可以在这样的“价值”上使用if语句吗? –
你可以测试一个对象的长度为0 – hrbrmstr