Skip to content

Instantly share code, notes, and snippets.

# Generalisation of the solution herE:
# https://stackoverflow.com/questions/37009120/create-matrix-based-upon-group-membership
hoodid <- c(1:10)
cityid <- c(1, 1, 1, 2, 2, 3, 3, 3, 3, 3)
df <- data.frame(hoodid, cityid)
df
# hoodid cityid
# 1 1 1