I would like to construct a dataframe row-by-row in R. I've done some searching, and all I came up with is the suggestion to create an empty list, keep a list index scalar, then each time add to the list a single-row dataframe and advance the list index by one. Finally, do.call(rbind,)
on the list.
While this works, it seems very cumbersome. Isn't there an easier way for achieving the same goal?
Obviously I refer to cases where I can't use some apply
function and explicitly need to create the dataframe row by row. At least, is there a way to push
into the end of a list instead of explicitly keeping track of the last index used?
append()
[which should probably be named insert] orc()
to add items to the end of a list, though won't help you here.lapply()
,Map()
, and so on, but you may also want to take a look ataggregate()
,dapply() {heR.Misc}
, andcast() {reshape}
to see if your tasks cannot be handled by these functions (these all return data frames).