I think countmap comes closest to giving you what you want:

using StatsBase
data = sample(["a", "b", "c"], 20)
countmap(data)


Dict{ASCIIString,Int64} with 3 entries:
  "c" => 3
  "b" => 10
  "a" => 7


On Sunday, August 17, 2014 4:45:21 PM UTC+3, Florian Oswald wrote:
>
> Hi
>
> I'm looking for the best way to count how many times a certain value x_i 
> appears in vector x, where x could be integers, floats, strings. In R I 
> would do table(x). I found StatsBase.counts(x,k) but I'm a bit confused by 
> k (where k goes into 1:k, i.e. the vector is scanned to find how many 
> elements locate at each point of 1:k). most of the times I don't know k, 
> and in fact I would do table(x) just to find out what k was. Apart from 
> that, I don't think I could use this with strings, as I can't construct a 
> range object from strings.
>
> I'm wondering whether a method StatsBase.counts(x::Vector) just returning 
> the frequency of each element appearing would be useful.
>
> The same applies to Base.hist if I understand correctly. I just don't want 
> to have to specify the edges of bins.
>
>
>

Reply via email to