For the moment, use array(). I need to finish a pull request that does these conversions properly using the convert() function.
-- John On Aug 26, 2014, at 2:55 PM, Bradley Setzler <[email protected]> wrote: > Following up on the changes in DataFrames Johan mentioned: > > The biggest difference I have found in DataFrames for Julia 0.3 is the > absence of the matrix() function. How can I quickly convert a DataFrame or > DataArray into an Array without matrix()? Here's an example of the issue: > > > Setup: > julia> X > 3x3 DataFrame > |-------|------|-----|-----| > | Row # | x1 | x2 | x3 | > | 1 | -1.0 | 0.0 | 1.0 | > | 2 | 2.0 | 3.0 | 4.0 | > | 3 | 5.0 | 6.0 | 7.0 | > > julia> y > 3-element DataArray{Float64,1}: > 1.0 > 0.0 > 1.0 > > Issue: > julia> linreg(X,y) > ERROR: `linreg` has no method matching linreg(::DataFrame, > ::DataArray{Float64,1}) > > > Old Solution: > julia> linreg(matrix(X),vec(matrix(y'))) > 4-element Array{Float64,1}: > 0.222222 > -0.222222 > 1.38778e-16 > 0.222222 > > > But matrix doesn't exist anymore. So I'm looking for commands that do the > following: > (1) Convert DataArray{Float64,1} into Array{Float64,1}. > (2) Convert DataFrame into Array{Float64,2}. > > How do you do this in Julia 0.3? > > Thanks, > Bradley > > > > > > On Monday, August 18, 2014 11:39:45 AM UTC-5, Johan Sigfrids wrote: > There are probably going to be quite a few changes in the DataFrames package > when you go from Julia 0.2 to 0.3. > > On Monday, August 18, 2014 7:28:48 PM UTC+3, Bradley Setzler wrote: > Thanks, Johan. I have upgraded to 0.3 release candidate and see what you mean > about scalar multiplication not working for DataFrame any more. I see also > that DataArray successfully converts Integer to Float in the way John was > describing earlier, which solves the original problem. > > Problem solved, thanks guys, > Bradley > > > > On Monday, August 18, 2014 10:32:25 AM UTC-5, Johan Sigfrids wrote: > Multiplying a DataFrame by a scalar has been deprecated and will not work > once you update to Julia 0.3 and the associated DataFrames version. > > On Monday, August 18, 2014 6:10:44 PM UTC+3, Bradley Setzler wrote: > Update: I found a 1-line command to convert everything in a DataFrame into a > Float that seems to work generally: > > data = data*1.0 > > So, for example, > julia> A=DataFrame([1 2 ; 3 4]) > 2x2 DataFrame: > x1 x2 > [1,] 1 2 > [2,] 3 4 > julia> A=A*1.0 > 2x2 DataFrame: > x1 x2 > [1,] 1.0 2.0 > [2,] 3.0 4.0 > > Best, > Bradley > > > > On Monday, August 18, 2014 10:02:02 AM UTC-5, Bradley Setzler wrote: > Hi John, > > Thanks for your reply, I'm getting the following: > > julia> A=DataArray([1 2; 3 4]) > 2x2 DataArray{Int64,2}: > 1 2 > 3 4 > julia> A*.5 > 2x2 DataArray{Float64,2}: > 0.5 1.0 > 1.5 2.0 > julia> A/2. > 2x2 DataArray{Float64,2}: > 0.5 1.0 > 1.5 2.0 > julia> A/2 > InexactError() > > So it converts to Float if divided by Float, but does not convert if divided > by Integer. > > Best, > Bradley > > > > On Monday, August 18, 2014 9:31:43 AM UTC-5, John Myles White wrote: > Hi Bradley, > > Would you consider using DataArrays for this? DataFrames no longer support > these operations, so any upgrade in your setup would turn all of this code > into errors. > > All of these operations work on DataArrays already. > > — John > > On Aug 18, 2014, at 7:28 AM, Bradley Setzler <[email protected]> wrote: > > > > > > > Good morning, > > > > I am looking for a simple way to convert an Integer DataFrame to a Float > > DataFrame. Here is an example of the problem: > > > > julia> using DataFrames > > julia> A=DataFrame([1 2; 3 4]) > > 2x2 DataFrame: > > x1 x2 > > [1,] 1 2 > > [2,] 3 4 > > > > With multiplication, there is no problem automatically converting to Float: > > > > julia> A*.5 > > 2x2 DataFrame: > > x1 x2 > > [1,] 0.5 1.0 > > [2,] 1.5 2.0 > > > > But with division, for example, the conversion fails: > > > > julia> A/2 > > InexactError() > > > > Ideally, there would be a one-line command so that we don't have to worry > > about this issue, say DataFloat() of the form: > > > > julia> A=DataFloat(A) > > 2x2 DataFrame: > > x1 x2 > > [1,] 1.0 2.0 > > [2,] 3.0 4.0 > > > > Does something like this exist? > > > > Thanks, > > Bradley > > >
