```
data(state) # US states
# convert matrix to data.table
states = data.table(state.x77, keep.rownames = "State")
# create weighted dataset
states_weighted = states %>%
let(
# calculate 'weight' variable.
weight = Population/100
) %>%
weight_by(weight)
# Each row in the weighted dataset is represented proportionally to the population of the state
nrow(states) # unweigthed number of cases
nrow(states_weighted) # number of cases in the weighted dataset
str(states_weighted)
```

Run the code above in your browser using DataLab