What's julia's answer to tapply or accumarray?

762 views
Skip to first unread message

James Johndrow

unread,
Mar 20, 2014, 1:46:33 PM3/20/14
to julia...@googlegroups.com
I cannot seem to find a built-in julia function that performs the function of tapply in R or accumarray in matlab. Anyone know of one?

Tom Short

unread,
Mar 20, 2014, 3:49:06 PM3/20/14
to julia...@googlegroups.com
The DataFrames package has operations on groupings:

http://juliastats.github.io/DataFrames.jl/split_apply_combine.html

It's more like PLYR than tapply, but it may be of use to you. I've
also been experimenting with some different APIs related to this:

https://github.com/JuliaStats/DataFramesMeta.jl#operations-on-groupeddataframes

Stefan Karpinski

unread,
Mar 20, 2014, 4:06:11 PM3/20/14
to Julia Users
A while ago, Alan sent this implementation of accumarray:

function accumarray(subs, val, fun=sum, fillval=0; sz=maximum(subs,1), issparse=false)
   counts = Dict()
   for i = 1:size(subs,1)
        counts[subs[i,:]]=[get(counts,subs[i,:],[]),val[i...]]
   end 
   A = fillval*ones(sz...) 
   for j = keys(counts)
        A[j...] = fun(counts[j])
   end
   issparse ? sparse(A) : A
end

It's not completely idiomatic, but it's pretty good and might be helpful.

phav...@gene.com

unread,
Oct 31, 2016, 3:38:06 PM10/31/16
to julia-users
RLEVectors.jl now has a tapply function where an RLE is used as the factor.

Chris Rackauckas

unread,
Oct 31, 2016, 11:06:28 PM10/31/16
to julia-users
For reference I've been gathering these kinds of "vectorized" functions in, well, VectorizedRoutines.jl. I am just trying to get an implementation of all of those vectorized routines you know and love since, in some cases, they lead to slick code. You can find an accumarray there. Feel free to add a PR that has more.

Peter Haverty

unread,
Nov 1, 2016, 5:27:29 PM11/1/16
to julia...@googlegroups.com
​It's great that you are making a collection of these. I see that you have a vectorized searchsortedfirst (findInterval).  I also felt the need for that one and have a version in RLEVectors.jl. I'll have a look at VectorizedRoutines.jl to see what I can contribute.​

Pete

____________________
Peter M. Haverty, Ph.D.
Genentech, Inc.
phav...@gene.com
Reply all
Reply to author
Forward
0 new messages