Create optimizedFlip

Needs work ... contains errors:

Warning message:
In mean.default(X[[3L]], ...) :
  argument is not numeric or logical: returning NA