Skip to content
Prev 178886 / 398503 Next

Corrupt data frame construction - bug?

On 29/04/2009 6:41 PM, Steven McKinney wrote:
I don't think "$" uses any data.frame machinery.  You are working at a 
lower level.

If you had added the new column using

bar <- data.frame(bar, NewCol=foo[foo[, 1] == 4, 4])

you would have seen the error:

Error in data.frame(bar, NewCol = foo[foo[, 1] == 4, 4]) :
   arguments imply differing number of rows: 3, 0

But since you treated it as a list, it let you go ahead and create 
something that was labelled as a data.frame but wasn't.  This is one of 
the reasons some people prefer S4 methods:  it's easier to protect 
against people who mislabel things.

Duncan Murdoch