[R] Inconsistency in 'names' when calling data.frame on other data.frames
Duncan Murdoch
murdoch@dunc@n @end|ng |rom gm@||@com
Fri Aug 21 19:39:02 CEST 2026
On 2026-08-21 12:01 p.m., Peter Langfelder wrote:
> Hi all,
>
> when calling data.frame on other data frames and naming arguments, the
> way the 'names' of the result are formed seems to depend on whether
> the argument data frames have one or more columns. Specifically,
> consider this:
>
>> data.frame(a = data.frame(A = 1), b = data.frame(B = 1))
> A B
> 1 1 1
>
>
> Here the column names are simply copied from column names of the arguments.
> In contrast, if the argument data frames have two (or more) columns,
> here's what happens:
>
>> data.frame(a = data.frame(A = 1, C = 1), b = data.frame(B = 1, D = 1))
> a.A a.C b.B b.D
> 1 1 1 1 1
>
>
> The 'names' of the result are now <name of the argument>.<column name
> of the argument value>
>
> Is this behavior intended?
It looks like it. From the help page: "For a named or unnamed
matrix/list/data frame argument that contains a single column, the
column name in the result is the column name in the argument."
However, also note how that paragraph started: "How the names of the
data frame are created is complex, and the rest of this paragraph is
only the basic story."
Duncan Murdoch
More information about the R-help
mailing list