Julia: An R-like apply function

Created on 29 Feb 2012  路  4Comments  路  Source: JuliaLang/julia

I don't see that there is an idiomatic way to map a function across a particular axis of an array, similar to the R "apply" function.

For example, for a matrix xs,

apply(xs, 1, mean)
apply(xs, 2, mean)

computes row and column means, respectively, and so on.

I want to implement a few statistics functions, and this (the R approach) seems more general and elegant than writing a special version of each that takes a dim argument (the Matlab approach, more or less). Functions like mean and median would then be computed over every element in the array.

Obviously the analogous Julia function would have to be called something other than apply. Perhaps "amap".

Before I get too far, is this approach agreeable?

Most helpful comment

(If, like me, you stumbled on this old issue from a web search: this functionality is now implemented in Base.mapslices.)

All 4 comments

Yes, I think we like this approach. In j/sort.j you'll find each_col! and each_row!, but obviously something more general is needed. Have to think more about what to call it.

Yes, this is much needed, and could simplify many things. I don't like the name apply because its a bit too generic to just use for something as specific as this. amap is good, but let's think the interface and implementation through.

I suggest that we really need to have everyone thinking about Julia from the R and NumPy/SciPy/Pandas points of view to organize around a roadmap for the types of data structures and data-manipulation routines that will be needed to eventually make Julia a serious competitor for interactive data exploration and analysis.

(If, like me, you stumbled on this old issue from a web search: this functionality is now implemented in Base.mapslices.)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omus picture omus  路  3Comments

yurivish picture yurivish  路  3Comments

i-apellaniz picture i-apellaniz  路  3Comments

TotalVerb picture TotalVerb  路  3Comments

helgee picture helgee  路  3Comments