I have a vector that I want to turn into a single row dataframe, this code works:
vec <- c("a","b","c","d","e")
df<- as.data.frame(t(as.data.frame(vec)))
but is so clunky, does anyone have a more elegant (and preferably less computationally expensive) solution
This might be one way :
data.frame(matrix(vec, 1))
# X1 X2 X3 X4 X5
#1 a b c d e
Or changing your approach to this instead.
data.frame(t(vec))
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