I\'m preparing data for a network meta-analysis and I am having difficult in tyding the columns.
If I have this initial dataset:
Study Trt y
We can gather to 'long' format, then unite multiple columns to single and spread it to wide
gather
unite
spread
wide
library(tidyverse) gather(df1, Var, Val, Trt:n) %>% group_by(Study, Var) %>% mutate(n = row_number()) %>% unite(VarT, Var, n, sep="") %>% spread(VarT, Val, fill=0)