how to transform a string into a factor and sets contrasts using dplyr/magrittr piping

Viewed 442

i have a rather specific question: how can I make a string into a factor and set its contrasts within a pipe ?

Let's say that I have a tibble like the following

tib <- data_frame (a = rep(c("a","b","c"),3, each = T), val = rnorm(9))

Now, I could use then two separate lines

tib$a <- factor(tib$a)
contrasts(tib$a) <- contr.sum(3)

But what If I wanted to perform the same actions within a pipe from dplyr ?

2 Answers
Related