While data frame columns must have the same number rows, is there any way to create a data frame of unequal lengths. I'm not interested in saving them as separate elements of a list because I often have to to email people this info as a csv file, and this is easiest as a data frame.
x = c(rep("one",2))
y = c(rep("two",10))
z = c(rep("three",5))
cbind(x,y,z)
In the above code, the cbind()
function just recycles the shorter columns so that they all have 10 elements in each column. How can I alter it just so that lengths are 2, 10, and 5.
I've done this in the past by doing the following, but it's inefficient.
df = data.frame(one=c(rep("one",2),rep("",8)),
two=c(rep("two",10)), three=c(rep("three",5), rep("",5)))
See Question&Answers more detail:os