nalimilan / FreqTables.jl

Frequency tables in Julia
Other
89 stars 19 forks source link

`prop` not working with categorical arrays? #37

Closed nickeubank closed 5 years ago

nickeubank commented 5 years ago
z = CategoricalArray(["a", "a", "b"])

3-element CategoricalArray{String,1,UInt32}:
 "a"
 "a"
 "b"

prop(z)

MethodError: no method matching prop(::CategoricalArray{String,1,UInt32,String,CategoricalString{UInt32},Union{}})
Closest candidates are:
  prop(!Matched::NamedArrays.NamedArray{#s27,N,AT,DT} where DT where AT where N where #s27<:Number, !Matched::Integer...) at /Users/Nick/.julia/packages/FreqTables/NHPMj/src/freqtable.jl:228
  prop(!Matched::AbstractArray{#s27,N} where N where #s27<:Number) at /Users/Nick/.julia/packages/FreqTables/NHPMj/src/freqtable.jl:220
  prop(!Matched::AbstractArray{#s27,N} where #s27<:Number, !Matched::Integer...) where N at /Users/Nick/.julia/packages/FreqTables/NHPMj/src/freqtable.jl:223

Stacktrace:
 [1] top-level scope at In[63]:1

No problems with freqtable:

freqtable(z)

2-element Named Array{Int64,1}
Dim1  │ 
──────┼──
a     │ 2
b     │ 1
nalimilan commented 5 years ago

prop computes proportions, so it needs Number entries (as documented).

nickeubank commented 5 years ago

OH! I see -- prop doesn't calculate proportions directly, it takes a frequency table as an input.

Out of curiosity, why the second step? why is it prop(freqtable(df, :some_var)) instead of just having prop work like freqtable, just with proportions rather than counts?

nalimilan commented 5 years ago

See https://github.com/nalimilan/FreqTables.jl/pull/19 and https://github.com/nalimilan/FreqTables.jl/issues/8. We can add proptable as a shorthand, but prop is useful in its own right so it was a good first step anyway.

nickeubank commented 5 years ago

Ah, ok. Yes, I think proptable would be a really nice function!

nalimilan commented 5 years ago

Feel free to make a PR if you want.

nickeubank commented 5 years ago

38