# Applying weights to Randomized Arrays In a Dataframe

**URL:** https://discourse.julialang.org/t/applying-weights-to-randomized-arrays-in-a-dataframe/65514
**Category:** Statistics
**Created:** [July 29, 2021, 7:00pm UTC](https://discourse.julialang.org/t/applying-weights-to-randomized-arrays-in-a-dataframe/65514 "2021-07-29T19:00:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![YummyPampers2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yummypampers2/32/27328_2.png) [@YummyPampers2](https://discourse.julialang.org/u/YummyPampers2)
#### Post date: [July 29, 2021, 7:00pm UTC](https://discourse.julialang.org/t/applying-weights-to-randomized-arrays-in-a-dataframe/65514/1 "2021-07-29T19:00:21Z")

</div>

Hello Everyone:

Is there a way to apply weights to arrays in  
a data such as:

```julia
DF = DataFrame(Id = 1:10, Tablets = (rand(1:02:50),10), Desktops =(rand(1:02:50),10), Mobiles = (rand(1:01:50), 10)) 

```

If I wanted to apply a 0.4, 0.5, 0.1 proportion to Tablets, Desktops, and Mobiles, How would I approach this? I am seeing, SimpleRandom.jl? I am seeing this package applies the probabilities via report(), but is there a way the probabilities can be applied to the data in the DataFrame?

Thanks.

---

<div class="post-metadata">

### Author: ![rmsmsgood](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rmsmsgood/32/20544_2.png) [@rmsmsgood](https://discourse.julialang.org/u/rmsmsgood)
#### Post date: [November 12, 2021, 4:32pm UTC](https://discourse.julialang.org/t/applying-weights-to-randomized-arrays-in-a-dataframe/65514/2 "2021-11-12T16:32:36Z")

</div>

`DF` is a 10-row dataframe and your question does not make sense to me. Actually, not relevant to `DataFrames` but try to use `StatsBase.sample`.

`sample(["Tablets", "Desktops", "Mobiles"], Weights([0.4,0.5,0.1]))`

Example:

```julia
using StatsBase
items = 0:5
weights = 0:5
sample(items, Weights(weights))

```

```julia
julia> my_samps = sample(items, Weights(weights), 10)
10-element Array{Int64,1}:
 4
 3
 2
 1
 3
 3
 5
 5
 2
 2

```
