r apply function to each column