Skip to content

Subsetting and conversion in data frames

1 message · Brian Ripley

#
I have now finished a long session of documenting and bug-fixing the way 
subscripting of data frames works -- you can see this in the NEWS file in 
R-devel.

As far as I know we are at the point where the only times that character
columns get converted to factors are in data.frame(), read.table() and
when as.data.frame() is called on a list.  (There are read.table-alikes in
other packages which will also convert.)  So if you have a character
column in a data frame, it should stay that way.

cbind.data.frame calls data.frame and so converts, and I believe it should
not.  There may be others (anyone know of any?).

This raises the possibility that using data.frame(I(foo)) could make foo a 
character column and not give it class "AsIs".   I've heard comments that 
having the additional class slows code down, but not seen any examples.
Any relevant experience or comments?