Yea, I was thinking about two different vectors, but then if I did any 
sorting, the value vector and weight vector would be out-of-sync.  I'll 
check out this StructsOfArrays package

Thanks!

Chris

On Monday, March 7, 2016 at 5:03:14 PM UTC-5, tshort wrote:
>
> It depends on what "various weighted statistical calculations" involves. 
> I'd start with two vectors, `x` and `w`. If you really need them to be 
> coupled tightly, you could define an immutable type to hold the value and 
> the weight, but the two separate vectors can be faster for some operations. 
> Also, see:
>
> https://github.com/simonster/StructsOfArrays.jl
>
> On Mon, Mar 7, 2016 at 4:50 PM, Christopher Alexander <[email protected] 
> <javascript:>> wrote:
>
>> Hello all, I need to create a structure where I keep track of pairs of 
>> value => weight so that I can do various weighted statistical calculations.
>>
>> I know that StatsBase has a weights vector, which I plan on using, but 
>> the way that is set up is that it is disassociated from each of the values 
>> to which the weights are to be applied.
>>
>> I need the mapping that "Pair" provides, but I've noticed that there is 
>> no easy way, if I have an array of pairs, to grab all the first values or 
>> all the second values (like you can do with a dict in grabbing keys or 
>> values).
>>
>> I've tried to do something like map(first, my_array_of_pairs), but this 
>> is about 10x slower than if you have a dictionary of value => weight and 
>> just asked for the keys.  I actually tried to use a dict at first, but ran 
>> into issues with duplicate values (they were overwriting each other because 
>> the value was the key).
>>
>> Any suggestions, or any better way to manipulate an array of Pairs?
>>
>> Thanks!
>>
>> Chris
>>
>
>

Reply via email to