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")
)
But ... :
> str(nouns)
'data.frame': 3 obs. of 2 variables:
$ V1: chr "gaggle" "dule" "wake"
$ V2: chr "geese" "doves" "vultures"
i.e. the col.names argument does nothing. From my reading of ?as.data.frame, my
example should have worked.
I know how to get the required result with colnames(), but I would like to
understand why the idiom as written didn't work, and how I could have known
that from the help file.
Thanks!
Boris
______________________________________________
[email protected] 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.