Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prop not working with categorical arrays? #37

Closed
nickeubank opened this issue Mar 20, 2019 · 6 comments
Closed

prop not working with categorical arrays? #37

nickeubank opened this issue Mar 20, 2019 · 6 comments

Comments

@nickeubank
Copy link
Contributor

nickeubank commented Mar 20, 2019

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
Copy link
Owner

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

@nickeubank
Copy link
Contributor Author

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
Copy link
Owner

See #19 and #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
Copy link
Contributor Author

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

@nalimilan
Copy link
Owner

Feel free to make a PR if you want.

@nickeubank
Copy link
Contributor Author

#38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants