Skip to content
Prev 395383 / 398502 Next

[Tagged] Re: col.names in as.data.frame() ?

Jef, your terse reply was so constructive that you converted me! LOL!

That is an interesting point though that I remain a bit unclear on. 

Both data.frame and as.data.frame can be used in some ways similarly as in:
X1 X2 X3 X4
1  1  4  7 10
2  2  5  8 11
3  3  6  9 12
V1 V2 V3 V4
1  1  4  7 10
2  2  5  8 11
3  3  6  9 12

But yes, the constructor accepts many arguments  while the converter really normally handles a single object.

Where do some other things like cbind() fit, not to mention a dplyr function like tribble()?

I do wonder though, why asking a converter to convert a matrix to a data.frame and perhaps adding column names, is considered changing the object contents. The manual page for as.data.frame seems to include quite a few options to specify the name of a single column, truncate column names, deal with row names, and more as well as whether to convert strings to factors. Are those things different enough than what we are discussing?

Of course, we may indeed be experiencing mission creep where something simple keeps being improved with new features until the original simplicity and clarity gets lost.


-----Original Message-----
From: R-help <r-help-bounces at r-project.org> On Behalf Of Jeff Newmiller via R-help
Sent: Saturday, October 28, 2023 2:54 PM
To: r-help at r-project.org; Boris Steipe <boris.steipe at utoronto.ca>; R. Mailing List <r-help at r-project.org>
Subject: Re: [R] [Tagged] Re: col.names in as.data.frame() ?

as.data.frame is a _converter_, while data.frame is a _constructor_.  Changing the object contents is not what a conversion is for.
On October 28, 2023 11:39:22 AM PDT, Boris Steipe <boris.steipe at utoronto.ca> wrote: