Skip to content
Prev 395346 / 398502 Next

Bug in print for data frames?

I would say this is not an error, but I think what you wrote isn't
what you intended to do anyway.

y[1] is a data.frame which contains only the first column of y, which
you assign to x$C, so now x$C is a data.frame.

R allows data.frame to be plain vectors as well as matrices and
data.frames, basically anything as long as it has the correct length
or nrow.

When the data.frame is formatted for printing, each column C is
formatted then column-bound into another data.frame using
as.data.frame.list, so it takes the name A because that's the name of
the column from y.

I think what you meant to do is x$C <- y[[1]]  ## double brackets
instead of single
On Thu, Oct 26, 2023 at 4:14?AM Christian Asseburg <rhelp at moin.fi> wrote: