Hello folks.
I am trying to pivot a very simple table from long format to a wide format.
I am getting these errors for some time now and there must be an easy way to solve it which I am not aware of.
Here is my code:
df <- data.frame(
Pain=c(sample(7:12,5,T),
sample(4:9,5,T),
sample(1:6,5,T)),
Expectation=factor(rep(c("Increase","Neutral","Decrease"),each=5)
))
This is fake data about the placebo effect of a medicine on pain perception. I generate it so the ones who expect high pain will report high levels of pain.
My code (that does not work):
df %>% pivot_wider(names_from = Expectation,
values_from = Pain)
Now,
in this case it is very simple to just write the code in a wide manner (either tribble or regular tibble), but this is not very helpful in future case.

The error I get from R looks like they're aware of the difficulties but still is not very helpful:
Pivot_longer syntax works like a charm though.
wide_df %>% pivot_longer(1:3,
names_to = "Expectation",
values_to = "Pain")