0

I'm seeking to compare a set of values from one column and I need to know if each one is bigger than one, so I can print a warning message that probably there was a typo inserting values in the beginning.

i=1:nrow(data)
if (m1$residuals[i] > 1) {
   print("typo")
}

This doesn't work, I get this message

Warning message:
In if (m1$residuals[i] > 1) { :
the condition has length > 1 and only the first element will be used

Why though?

Can someone tell me an alternative way to do it?

Thank you

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jah-Lahfui
  • 35
  • 5
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Oct 08 '19 at 14:45

2 Answers2

0

Try this and see.

if(all((m1$residuals>1)==TRUE)){
print("typo")
}
Rlearner
  • 93
  • 5
0

Do you want to know if at least one of the values in the column exceeds 1? If so you could try

if (any(m1$residuals > 1)) {
   print('typo')
}

If you want to check if all the values are greater than 1, replace the 'any' with 'all'.

user2474226
  • 1,472
  • 1
  • 9
  • 9