0

I'm trying to convert this wide format

Wide format

into

Long format

I tried this code

test <- Gil.Q4 %>% 
      select(id, x1:z3) %>%
      gather(n1, grade, x1, y1, z1) %>%
      gather(n2, grade, x2, y2, z2) %>%
      gather(n3, grade, x3, y3, z3)

But it is not working. Please help

Jaap
  • 81,064
  • 34
  • 182
  • 193
Ezenwa
  • 1
  • 3
  • Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). This will make it much easier for others to help you. – Jaap Feb 27 '16 at 07:16
  • In your case I would use: `library(data.table); melt(setDT(Gil.Q4), measure = patterns("1","2","3"), value.name = c("val1","val2","val3"), variable.name = "class")[, class := c("a","b","c")[class]]` to get what you want. – Jaap Feb 27 '16 at 07:38

0 Answers0