Skip to content
Prev 22349 / 398502 Next

I know this is wrong, but why?

Stuart Luppescu <s-luppescu at uchicago.edu> writes:
The main thing is that R generally deals in entire vectors and that
if-statements will only make one decision, never do one thing for some
elements and something else for the rest. In  if (effects1[,3] < 0 &
effects0[,3] < 0)  the condition is a vector. but only the first
element is used, as in
[1]  TRUE  TRUE FALSE
[1]  TRUE FALSE  TRUE

for by-element decisions consider ifelse(), or, as you did, indexing.