1

DATA

i have a data frame like this:

 id weigth temp_s1 temp_s2
  1     50       2       7
  2     51       3       8
  3     52       4       9
  4     53       5      10
  5     54       6      11

What i want

I would like to obtain this:

     id weigth  temp    value
      1     50  temp_s1     2
      1     50  temp_s2     7
      1     51  temp_s1     3
      1     51  temp_s2     8
      1     52  temp_s1     4
      1     52  temp_s2     9
      1     53  temp_s1     5
      1     53  temp_s2     10
      1     54  temp_s1     6
      1     54  temp_s2     11
michal.jakubeczy
  • 8,221
  • 1
  • 59
  • 63
Orhan Yazar
  • 909
  • 7
  • 19

1 Answers1

3

You should use melt function from reshape2 package as follows:

melt(df, c("id", "weight"))
Pop
  • 12,135
  • 5
  • 55
  • 68