Hi folks,

I KNOW there has to be a way to do this more elegantly, but I
consistently fail to come up with it, as I was just reminded while
writing an example for a query on this list.

What's a nifty way to construct a data frame of a given size? The only
way I know of it to use matrix(), eg

data.frame(matrix(NA, nrow=10, ncol=3))

and then to set the colnames in a second step.

This comes up a lot when pre-allocated a data frame before using a
loop: I know the size and column names, but want an empty structure to
fill later.

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to