I would like to know a practical way to transform dat in the table below
dat <- data.frame('city' = c('A','A','B','C','A','B','B','C','C','C'),
'color' = c('red', 'green', 'blue', 'red', 'green', 'blue', 'green', 'blue', 'red', 'red'),
'sex' = c('M','F','F','M','F','F','F','M','F','M'))
city red green blue F M
A 1 2 0 2 1
B 0 1 2 3 0
C 3 0 1 1 3