Skip to content
Prev 318633 / 398506 Next

if value is in vector, perform this function

I forgot to say:

Also do not depend on equality in this situation.
You want to test equality with a tolerance.

See Circle 1 of 'The R Inferno':
http://www.burns-stat.com/documents/books/the-r-inferno/

I also see that 't' is a vector unlike what I was
thinking before, thus you want to use 'ifelse':

C_A <- ifelse(t %in% feed_days, 1.5, 0)

except that still leaves out the tolerance.  If
you are always only going to go by half-days, then
the following should work:

C_A <- ifelse( round(2*t) %in% round(2 * feed_days), 1.5, 0)

Pat
On 02/03/2013 23:57, Louise Stevenson wrote: