が、私はグループでの変数の平均値を計算するためにaggregate
機能を使用しようとしていますと、Julia:IndexedTables.jlの集計を使ってグループごとに平均を計算する方法は?
using Distributions, PooledArrays
N=Int64(2e9/8); K=100;
pool = [@sprintf "id%03d" k for k in 1:K]
pool1 = [@sprintf "id%010d" k for k in 1:(N/K)]
function randstrarray(pool, N)
PooledArray(PooledArrays.RefArray(rand(UInt8(1):UInt8(K), N)), pool)
end
using JuliaDB
DT = IndexedTable(Columns([1:N;]), Columns(
id1 = randstrarray(pool, N),
v3 = rand(round.(rand(Uniform(0,100),100),4), N) # numeric e.g. 23.5749
));
res = IndexedTables.aggregate(mean, DT, by=(:id1,), with=:v3)
MethodError: no method matching mean(::Float64, ::Float64)
Closest candidates are:
mean(!Matched::Union{Function, Type}, ::Any) at statistics.jl:19
mean(!Matched::AbstractArray{T,N} where N, ::Any) where T at statistics.jl:57
mean(::Any) at statistics.jl:34
in at base\<missing>
in #aggregate#144 at IndexedTables\src\query.jl:119
in aggregate_to at IndexedTables\src\query.jl:148
しかし
IndexedTables.aggregate(+ , DT, by=(:id1,), with=:v3)
が正常に動作します
私はOPが望んでいないことを確信しています - 私は彼がv3によって与えられたすべてのグループのv3値の平均を望んでいると思う - つまり、 'tapply(DT $ v3、DT $ id1、mean) 'Rで; dataFrames内のgroupby(DT、:id1)]のsubdfの '[mean(subdf [:v3]) 'です。 –
私はジュリアにtapplyを持っていたいと思う(私はそれがRLEVectors.jlであることを知っているが、それは少しclunky感じている) –
@ MichaelK.Borregaardはい私はグループによって値の平均を取ることについて考えている。 – xiaodai