0

I have a dataframe that is shaped like this:

    data <- data.frame("subject" = c("John", "David", "Julia", "Anna"), "att1" = c("A", "A", "B", "C"), 
               "value1" = runif(4, 1, 2), "att2" = c("B", "C", "A", "A"), "value2" = runif(4,1,2))

  subject att1   value1 att2   value2
1    John    A 1.884899    B 1.695328
2   David    A 1.352952    C 1.543145
3   Julia    B 1.929525    A 1.000639
4    Anna    C 1.486212    A 1.722314

I want it to look like this:

  subject att    value
1    John   A 1.884899
2    John   B 1.695328
3   David   A 1.352952
4   David   C 1.543145
5   Julia   B 1.929525
6   Julia   A 1.000639
7    Anna   C 1.486212
8    Anna   A 1.722314

I know that hat I need has something to do with gatherfunction from tidyr, but I cant' make it work. It's important to note that my original data has much more columns with pairs of values and attributes that I need to condense. Thanks in advance!

David Jorquera
  • 2,046
  • 12
  • 35

0 Answers0