After much experimenting and googling... and subsequent experimenting again, I am finally resulting to asking my first question on StackOverflow :)
I have a data.frame, and want to apply a custom function, expandBases
, to each row of the data.frame. expandBases
returns a data.frame consisting of 1 or more rows (and this will vary depending on the data supplied to it). expandBases
actually returns more columns than in the toy example below -- but for the sake of illustration:
structure(list(id = structure(1:3, .Label = c("a", "b", "c"), class = "factor"),
startpos = c(1, 2, 3), len = c(1, 2, 3)), .Names = c("id",
"startpos", "len"), row.names = c(NA, -3L), class = "data.frame")
expandBases <- function(startpos, len)
{
return(data.frame(cy <- startpos + 0:(len - 1)))
}
I would like the id
factor to be replicated for each row of the returned data.frame. I've been told to use lapply + do.call(rbind). I was wondering if there is a plyr-based solution to this?
Thanks in advance.