I have a list like this
A <- data.frame(a = c(1, 2), b = c(3, 4))
B <- data.frame(c = c(1, 2), d = c(3, 4))
g <- list(var1 = A, var2 = B)
producing
> g
$var1
a b
1 1 3
2 2 4
$var2
c d
1 1 3
2 2 4
Now I want to transpose list elements like this
lapply(g, function(x) data.frame(t(x)))
but this produces a, b, c d, as rownames which is not what I want
> lapply(g, function(x) data.frame(t(x)))
$var1
X1 X2
a 1 2
b 3 4
$var2
X1 X2
c 1 2
d 3 4
I would like to generete a new column into these data.frames for a, b, c, and d. How to achieve this?