Iteration using vectorization and apply