dplyr Tidbits

Row-wise random function

Apply a random function to each row (i.e., each row should have a different random number). With only mutate, the whole new column will get the same random number. The trick is to use rowwise() before mutate:

iris %>% rowwise() %>% mutate( new = rnorm(n(),0,1))