Added cast
Added R-style apply. Cazart