2

I have a data frame with counts of each combination of a trait (true / false) for species A and B. Here's a smaller version of my data:

species <- c("A", "B") 
true <- c(3, 2) 
false <- c(1, 4) 
df <- data.frame(species, true, false)
df
  species true false
1       A    3     1
2       B    2     4

Is there any way to convert these summarized counts to one row for each registration, with first column for "Species" (A or B). Second column "Trait" (true or false):

Species    Trait
      A     true
      A     true
      A     true
      B     true
      B     true
      A    false
      B    false
      B    false
      B    false
      B    false

I don´t really know how to approach this, usually raw data is available and a summary table can easily be constructed from that, but this is the reverse way.

I´m thankful for every answer! :)

Henrik
  • 61,039
  • 13
  • 131
  • 152
Arsen
  • 21
  • 1

0 Answers0