Tuesday 15 March 2011

r - Compare each member of a vector with its number -



r - Compare each member of a vector with its number -

the problem might simple, cant solve it: got numeric vector, need compare maximum/2 each fellow member except maximum , if these comparisons false , a=a+1. got these:

comp=c(6.674971, 11.208241, 18.296459, 5.165752, 123.000000) a=0 if (max(comp)/2<comp[comp < max(comp)]){ a=a+1 }

thank in advance.

the status true if :

sum(2*comp > max(comp)) ==1

in case , write without using ìf:

<- (sum(2*comp > max(comp)) ==1) + 1

r

No comments:

Post a Comment