0

My data is set up like this:

PUBLISH_DATE   SORT_ORDER     Problems
12/01/11       1              Persistent Slabs
12/01/11       2              Wind Slabs
12/02/11       1              Storm Slabs
12/02/11       2              Wind Slabs
12/02/11       3              Persistent Slabs
etc...

What I would like to do is format it like this:

PUBLISH_DATE   Sort_Order1       Sort_Order2     Sort_Order3
12/01/11       Persistent Slabs  Wind Slabs      NA
12/02/11       Storm Slabs       Wind Slabs      Persistent Slabs

I've used the following to get this output:

new_data <- dcast(test_data, PUBLISH_DATE ~ SORT_ORDER) 

which gives me this:

PUBLISH_DATE     1       2       3
12/01/11         1       1       0
12/02/11         1       1       1

But I can't figure out how to replace the number values of each column with the assigned Problem.

HELP?

Jaap
  • 81,064
  • 34
  • 182
  • 193
  • YOu may need the `value.var` i.e. `dcast(test_data, PUBLISH_DATE ~ paste0("sort_order", SORT_ORDER), value.var = "Problems")` If there are duplicate elements, add `PUBLISH_DATE + rowid(PUBLISH_DATE) ~` – akrun Jun 06 '18 at 21:01
  • Related: [*dcast error: ‘Aggregation function missing: defaulting to length’*](https://stackoverflow.com/questions/33051386/dcast-error-aggregation-function-missing-defaulting-to-length) – Jaap Aug 31 '18 at 05:25

0 Answers0