My question has strong similarities with this one and this other one, but my dataset is a little bit different and I can\'t seem to make those solutions work. Please excuse me i
library(tidyr) library(dplyr) df <- df %>% gather(type, count, -id) df <- df[complete.cases(df),][,-3] df[order(df$id),] id type 1 1 conditionA 7 2 conditionB 13 3 conditionC 19 4 conditionD 5 5 conditionA