Rearranging data frame from column names to key value pairs If I have data like this in R:

&gt; a = data.frame(a = c(1, 2),
               b = c(3, 4))
&gt; a
  a b
1 1 3
2 2 4


but I would like to have it like this:

&gt; b = data.frame(k = c("a", "a", "b", "b"),
+                v = c(1, 2, 3, 4))
&gt; b
  k v
1 a 1
2 a 2
3 b 3
4 b 4



How can I convert the data this way?
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