Search code examples
rdataframedplyrtibble

How can I use columns as entries in rows?


in the attached picture you can see two dataframes. I want to transform the first dataframe to the second one. I feel like there is probably an easy solution, I just don't know it.

Two Dataframes

Note that this example is created in Excel, the "real work" will be done in R.


Solution

  • You need pivot_longer.

    library(tidyr)
    
    df %>%
      pivot_longer(cols=starts_with("Gene"), names_to="Gene", values_to="Count")