Thanks for the answer. I tried "eachrow" but I have 2 problems :

1- I still have to do an array conversion, I think it is slow

julia> for r in eachrow(df) 
              println(mean(convert(Array,r))) 
       end 
6.0 
7.0 
8.0 
9.0 
10.0



2- I do not manage to use a subset of the row, for example the 2 first 
values :
julia> for r in eachrow(df) 
              println(mean(convert(Array,r))) 
       end 
6.0 
7.0 
8.0 
9.0 
10.0 
 
julia> for r in eachrow(df) 
              println(mean(convert(Array,r[1:2]))) 
       end 
WARNING: [a] concatenation is deprecated; use collect(a) instead 
 in depwarn at deprecated.jl:73 
 in oldstyle_vcat_warning at ./abstractarray.jl:29 
 [inlined code] from none:2 
 in anonymous at no file:0 
while loading no file, in expression starting on line 0 
4.0
 





Le samedi 21 novembre 2015 14:04:11 UTC+1, tshort a écrit :
>
> You can try `eachrow`. It probably won't be fast, though. Here's an 
> example:
>
>
> https://github.com/JuliaStats/DataFrames.jl/blob/master/test/iteration.jl#L34
> On Nov 21, 2015 7:19 AM, "Fred" <fred.so...@gmail.com <javascript:>> 
> wrote:
>
>> Hi,
>>
>> In DataFrames, it is easy to apply a function by columns using the 
>> colwise() function. But I find very difficult and inefficient to apply a 
>> function by rows.
>>
>> For example :
>>
>>
>>  
>>  julia> df = DataFrame(a=1:5, b=7:11, c=10:14) 
>> 5x3 DataFrames.DataFrame 
>> | Row | a | b  | c  | 
>> |-----|---|----|----| 
>> | 1   | 1 | 7  | 10 | 
>> | 2   | 2 | 8  | 11 | 
>> | 3   | 3 | 9  | 12 | 
>> | 4   | 4 | 10 | 13 | 
>> | 5   | 5 | 11 | 14 | 
>>
>>  
>>  
>>  julia> colwise(mean,df) 
>> 3-element Array{Any,1}: 
>>  [3.0]  
>>  [9.0]  
>>  [12.0]
>>  
>>  
>>  julia> colwise(mean,df[1,1:2]) 
>> 2-element Array{Any,1}: 
>>  [1.0] 
>>  [7.0]
>>
>>
>>
>> To calculate the mean of a row (or a subset), the only way I found is 
>> this :
>>
>> julia> mean(convert(Array,df[1,1:3])) 
>> 6.0
>>  
>>
>>
>> I think this is inefficient and probably very slow. I there a better way 
>> to apply a function by rows ?
>>
>> Thanks !
>>
>

Reply via email to