Sent a slightly shorter version of this to your email, this one is to
the list:
On 28/10/2023 1:54 p.m., Boris Steipe wrote:
> > I have been trying to create a data frame from some structured text
in a single expression. Reprex:
> >
> > nouns <- as.data.frame(
> > matrix(c(
> > "gaggle",
> > "geese",
> >
> > "dule",
> > "doves",
> >
> > "wake",
> > "vultures"
> > ), ncol = 2, byrow = TRUE),
> > col.names = c("collective", "category")
> > )
> >
You are calling it on a matrix, so the as.data.frame.matrix method is
what matters. It doesn't have a col.names argument, only row.names.
The docs are vague about what ... does, but if you look at the method,
you can see any unnamed arguments are ignored completely.
If you want to specify the column names in a single call, you'll need to
put them in the matrix, e.g.
as.data.frame(
matrix(c(
"gaggle",
"geese",
"dule",
"doves",
"wake",
"vultures"
), ncol = 2, byrow = TRUE,
dimnames = list(NULL, c("collective", "category"))
)
)
Duncan Murdoch
______________________________________________
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.