convert works beautifully. Thank you.
On Friday, December 25, 2015 at 3:18:25 PM UTC-5, Ismael Venegas Castelló
wrote:
>
> Min-Woong you could use convert, it works with NAs and you still get an
> error for free if conversion is not possible:
>
> julia> df = DataFrame(x = @data [1,2,3, NA, typemax(Int8)])
> 5x1 DataFrames.DataFrame
> | Row | x |
> |-----|-----|
> | 1 | 1 |
> | 2 | 2 |
> | 3 | 3 |
> | 4 | NA |
> | 5 | 127 |
>
> julia> eltype(df[:x])
> Int64
>
> julia> df[:x] = convert(DataArray{Int8, 1}, df[:x]);
>
> julia> eltype(df[:x])
> Int8
>
> julia> df = DataFrame(x = @data [1,2,3, NA, typemax(Int8) + 1])
> 5x1 DataFrames.DataFrame
> | Row | x |
> |-----|-----|
> | 1 | 1 |
> | 2 | 2 |
> | 3 | 3 |
> | 4 | NA |
> | 5 | 128 |
>
> julia> eltype(df[:x])
> Int64
>
> julia> df[:x] = convert(DataArray{Int8, 1}, df[:x]);
> ERROR: InexactError()
> in copy! at abstractarray.jl:302
>
>
>
> El jueves, 24 de diciembre de 2015, 5:02:14 (UTC-6), Min-Woong Sohn
> escribió:
>>
>> I want to reduce the amount of memory used by a dataframe that has lots
>> of binary variables. What is the best way to achieve this? For example, how
>> can I convert a variable from Int64 to Int8 in a dataframe.
>>
>> Thanks
>>
>