0

Did some extensive searching but couldn't find a solution. I have a dataframe that looks like this:

FAC | NUM | VAL
A   | 1   | 100
A   | 2   | 200
B   | 1   | 300
B   | 2   | 200

And I want it to look like this:

NUM | A   | B  
1   | 100 | 300
2   | 200 | 200

Is there any simple way to use mutate() in dplyr (potentially in combination with base R) to achieve this goal?

Any support would be appreciated.

Stu Richards
  • 141
  • 1
  • 11
  • `reshape(df, idvar = "NUM", timevar = "FAC", direction = "wide")` . I am not sure if you can do this with `mutate` in `dplyr` – Ronak Shah Aug 10 '17 at 04:39
  • Using `reshape2` package's `dcast` function: dcast(data = df,formula = NUM~FAC) – tushaR Aug 10 '17 at 04:44
  • look into the `spread()` function [here](https://www.rstudio.com/wp-content/uploads/2015/02/data-wrangling-cheatsheet.pdf) – Aramis7d Aug 10 '17 at 04:49
  • Hi all - thanks for the support here. @Aramis7d the spread function worked a charm. Sure the others worked perfectly well too. – Stu Richards Aug 10 '17 at 04:59

0 Answers0