[R] idiom for constructing data frame

Sarah Goslee sarah.goslee at gmail.com
Tue Mar 31 20:37:03 CEST 2015


Duncan Murdoch suggested:

> The matrix() function has a dimnames argument, so you could do this:
> names <- c("strat", "id", "pid")
> data.frame(matrix(NA, nrow=10, ncol=3, dimnames=list(NULL, names)))

That's a definite improvement, thanks. But no way to skip matrix()? It
just seems unRlike, although since it's only full of NA values there
are no coercion issues with column types or anything, so it doesn't
hurt. It's just inelegant. :)

Sarah Goslee

More information about the R-help mailing list