Skip to content
Prev 238000 / 398500 Next

Building ragged dataframe (was Re: Data Gaps)

<snip>

Leaping in on a detail, and apologising in advance if my comment isn't 
relevant, I had need to build up a data frame from different length columns 
(a ragged dataframe?). In case it helps, this function is what I ended up 
with...
---------------
 # utility function, combining different length objects into a dataframe
 # padding short columns with NA
 CDF <- function(x, y)
 { out <- merge(data.frame(x), data.frame(y), all = T, by = "row.names") # 
merge
  out$Row.names <- as.integer(out$Row.names) # make row names integer
  data.frame(out[order(out$Row.names), -1], row.names = 1:length(out[[1]])) 
# sort
 }
----------------

I guess it could reasonably easily be extended to more than two arguments. 
This met my needs, and I didn't look very hard for alternatives, so there 
may be better approaches.

HTH

Keith J