SubDataFrame to DataFrame

I was trying to use a function that not accept SubDataFrames inside by() (in particular I found that there is not way to get a DataFrame from a SubDataFrame. It would be great to have a convert method to use in this kind of cases (even if it generates copies).

I thought we had a converter at one time. Anyway, it’s easy to write:

todf(x::SubDataFrame) = x.parent[x.rows,:]

It does make copies. To avoid copies, you could convert to a DataFrame where each column is a view into the original.That’s a bit more work, so consider that an exercise for the reader :slight_smile: .

Actually, the column view version is pretty easy, too. Note: not tested much.

todfview(x::SubDataFrame) = DataFrame(Any[view(col, x.rows) for col in x.parent.columns], names(x))

Doesn’t copy on a view of type T always create an object of type T?
Of course in this case it may be cool to not copy. And as @Diego_Javier_Zea notes in his issue the solution should be to define the function on AbstractDataFrame.

I tried these on Julia 0.7 but it doesn’t seem to work… Is there a new / easiest way to convert a subdatframe to a dataframe?