Rearranging data frame from column names to key value pairs
This is a simple gather() using package tidyr:

&gt; library(tidyr)
&gt; 
&gt; gather(a, key = "k", value = "v")
  k v
1 a 1
2 a 2
3 b 3
4 b 4