I have a list like this:
arg0 <- list(code = "a", n = rep(10, 3))
The number of objects in a list is variable. The objects of the list are vectors -- only one dimensional objects.
I want to make a procedure to convert the list to a one row data.frame like this:
> data.frame(code = "a", n.1 = 10, n.2 = 10, n.3 = 10)
code n.1 n.2 n.3
1 a 10 10 10
I have this solution currently:
a <- stack(arg0)
b <- data.frame(t(a[,1]))
names(b) <- a[,2]
b <- data.frame(b)
Where b
is almost the result I want to achieve:
> b
code n n.1 n.2
1 a 10 10 10
Two questions:
c(n.1,
n.2, n.3)
?This is one way:
data.frame(t(unlist(arg0)))
# code n1 n2 n3
# 1 a 10 10 10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With