Yes, the DataArrays package exists to handle `NA` elements as a foundation
for DataFrames.
You've stumbled upon an open issue in the language, and you're exactly
right: vectorization like this is really handy, but it can make reading
code a bit harder to understand. In this case, for example, right now
everyone who knows Julia will expect Float64(x) to return a Float64,
regardless of what x is. If we auto-vectorize the Float64 constructor,
that will no longer be the case.
Here are some alternatives:
map(Float64, full_frl_college[:jun_sen]) # not very fast on 0.4, will be
much better on 0.5
convert(Array{Float64}, full_frl_college[:jun_sen]) # note that you can
omit the dimensionality
convert(AbstractArray{Float64}, full_frl_college[:jun_sen]) # this will try
to keep the outer array type the same
Converting directly to a DataArray, like you tried, should probably work
and may be a missing method in DataArrays.jl.
On Friday, March 18, 2016 at 3:13:00 PM UTC-4, Lewis Levin wrote:
>
> Here is a simple statement:
> full_frl_college[:jun_sen] = Float64(full_frl_college[:jun_sen])
>
> Here is the resulting error message:
>
> LoadError: MethodError: `convert` has no method matching
> convert(::Type{Float64}, ::DataArrays.DataArray{Int64,1})
>
>
> What is the right approach to this conversion? I tried
> convert(DataArrays.DataArray{Float64,1}, full_frl_college[:jun_sen])
> which did not work.
>
> Answering my own question, both of these work:
> x = Array{Float64,1}(collect(full_frl_college[exist, :jun_sen]))
> # or
> full_frl_college[:jun_sen]=Array{Float64,1}full_frl_college[:jun_sen]
> # note the collect() above is NOT needed
>
> So, all is good.
>
> My confusion was taking the error message too literally and trying to
> convert using the DataArray type. Does the DataArrays.DataArray type
> enable DataFrames to do its NA handling? If so, then I'd really want to use
> that type rather than Array{Float64, N}. For this data, I'd already purged
> the NAs so it didn't matter.
>
> Obviously, dimensionality is part of the type of the starting and target
> types. Perhaps that is a bit too restrictive. Is it possible that if a
> conversion will be, in effect, an element-wise conversion of the entire
> contents of the array that the conversion/promotion should be allowed? I
> realize that with mixed types it can be unclear what a conversion "means".
> But, when the object is already of one type and the target is of one type
> it seems intuitive to just do the conversion even if the types, strictly
> speaking, don't match because of dimensionality. I guess this is a request
> for "element-wise" conversion.
>
> Seems like this would make Julia more approachable. Also, it could make
> the job of package developers, working with arrays and matrices, a bit
> easier because they wouldn't need methods for as many cases.
>
>