So I'm trying to loop through some data and use them in my code. The place where I need this try thing is at the following:
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)
}
The thing is that the CTV_volume
calculation in the two last lines (large_volume
and small_volume
) depends on data from the first line above (CTV_volume
). However, for each iteration of the loop there is a chance that there is no CTV for that particular key/number, and instead I need to use another one, i.e. ITV. But first and foremost I need it to use the CTV first if that is present, and if not, then the ITV word.
How is that accomplished in R?
numeric(0)
instead of a number. Can one use an if statement on such a "value" ? – Denver Dang Oct 21 '17 at 10:48