{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaStats/StatsBase.jl/issues/223","repository_url":"https://api.github.com/repos/JuliaStats/StatsBase.jl","labels_url":"https://api.github.com/repos/JuliaStats/StatsBase.jl/issues/223/labels{/name}","comments_url":"https://api.github.com/repos/JuliaStats/StatsBase.jl/issues/223/comments","events_url":"https://api.github.com/repos/JuliaStats/StatsBase.jl/issues/223/events","html_url":"https://github.com/JuliaStats/StatsBase.jl/issues/223","id":187927008,"number":223,"title":"countmap should sort values","user":{"login":"femtotrader","id":5049737,"avatar_url":"https://avatars.githubusercontent.com/u/5049737?v=3","gravatar_id":"","url":"https://api.github.com/users/femtotrader","html_url":"https://github.com/femtotrader","followers_url":"https://api.github.com/users/femtotrader/followers","following_url":"https://api.github.com/users/femtotrader/following{/other_user}","gists_url":"https://api.github.com/users/femtotrader/gists{/gist_id}","starred_url":"https://api.github.com/users/femtotrader/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/femtotrader/subscriptions","organizations_url":"https://api.github.com/users/femtotrader/orgs","repos_url":"https://api.github.com/users/femtotrader/repos","events_url":"https://api.github.com/users/femtotrader/events{/privacy}","received_events_url":"https://api.github.com/users/femtotrader/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2016-11-08T08:11:08Z","updated_at":"2016-11-14T19:59:53Z","closed_at":null,"body":"According doc http://statsbasejl.readthedocs.io/en/latest/counts.html#countmap\r\n`countmap` returns a dictionary that maps distinct values in x to their counts (or total weights).\r\n\r\nIt may be useful to sort these values (using ascending order)\r\n\r\nSo maybe an OrderedDict may be a better data structure for this.\r\n\r\nUse case:\r\nWhen you define a timeseries, it may help to find the most prevalent period between 2 timestamps (sampling period).\r\nYou will have to sort this OrderedDict using descending order of values\r\nMost prevalent period will be the first value of this OrderedDict.\r\n\r\nWhen timestamps are regulary spaced you get a dict with only one key (for which value is sampling period)\r\n\r\nPython Pandas have a `value_counts` property for Series which is very useful.\r\nhttp://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.value_counts.html\r\n"},"comment":{"url":"https://api.github.com/repos/JuliaStats/StatsBase.jl/issues/comments/260445213","html_url":"https://github.com/JuliaStats/StatsBase.jl/issues/223#issuecomment-260445213","issue_url":"https://api.github.com/repos/JuliaStats/StatsBase.jl/issues/223","id":260445213,"user":{"login":"femtotrader","id":5049737,"avatar_url":"https://avatars.githubusercontent.com/u/5049737?v=3","gravatar_id":"","url":"https://api.github.com/users/femtotrader","html_url":"https://github.com/femtotrader","followers_url":"https://api.github.com/users/femtotrader/followers","following_url":"https://api.github.com/users/femtotrader/following{/other_user}","gists_url":"https://api.github.com/users/femtotrader/gists{/gist_id}","starred_url":"https://api.github.com/users/femtotrader/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/femtotrader/subscriptions","organizations_url":"https://api.github.com/users/femtotrader/orgs","repos_url":"https://api.github.com/users/femtotrader/repos","events_url":"https://api.github.com/users/femtotrader/events{/privacy}","received_events_url":"https://api.github.com/users/femtotrader/received_events","type":"User","site_admin":false},"created_at":"2016-11-14T19:59:53Z","updated_at":"2016-11-14T19:59:53Z","body":"@andreasnoack  I know this, with https://github.com/JuliaLang/DataStructures.jl/pull/225 we should be able to do\r\n\r\n```julia\r\nusing DataStructures\r\nd = sort(countmap(a), byvalue=true)\r\n```\r\n\r\nwhich can be quite good for dict with few keys/values\r\n\r\nbut I like @ararslan idea of defining\r\n\r\n```julia\r\ncountmap{T<:Associative}(::Type{T}, ...)\r\n```\r\n\r\nbecause if a `SortedDict` is passed, `countmap` will be sort using keys.\r\n\r\nWe just need to find a `SortedValuesDict` which sort Dict using values"}}
{"actor":{"display_login":"femtotrader"}}