The apply functions in R are awesome (see this post for some lesser known apply functions). However, if you can…