[R] col.names in as.data.frame() ?
Boris Steipe
bor|@@@te|pe @end|ng |rom utoronto@c@
Sat Oct 28 19:54:27 CEST 2023
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
More information about the R-help
mailing list