Some useful r code