if condition in looping

Hi,

Im running loops over a huge dataset.
In short terms im predicting heigth with weigth, using a model ive developed.
I have the true/observed value for heigth.

After running the script my results consists of about 260 000 rows.
My problem is that the model sometimes predict the height extremely wrong.
Giving values both positive and negative in the millions (where true value is somewhere between 0-30)

I would like to predict heigth with a different model (that I know works fine) if the predicted value from the original model is +- 50% from the true value.

if(p.Heigth differs more than 50% from observed.H)
Use model 2 to predict heigths instead.

Ive tried to set up a if() statement like that but since my dataframe has several rows it only returns me a warning saying it can only test 1 row.

Something like

correctValue <- ifelse(firstPrediction>=0 & firstPrediction<=30,
 firstPrediction,
 secondPredictionFunction())

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.