Restructuring data in R

I am just starting to go beyond the basics of R and come to the point where I need help. I want to restructure some data. Here is an example of an example data frame:

ID  Sex Res Contact
1   M   MA  ABR
1   M   MA  CON
1   M   MA  WWF
2   F   FL  WIT
2   F   FL  CON
3   X   GA  XYZ

I want the data to look like this:

ID  SEX Res ABR CON WWF WIT XYZ
1   M   MA  1   1   1   0   0
2   F   FL  0   1   0   1   0
3   X   GA  0   0   0   0   1

What are my options? How do I do this in R?

In short, I want to save the values ​​of the CONT column and use them as the column names in the restructured data frame. I want the variable column group to be constant (in the above example, I held the identifier, gender, and constant constant Res).

Also, is it possible to manage values ​​in restructured data? I can save the data as binary. I may need some data to have a value equal to the number of times each contact value for each identifier.

+5
2

reshape - , . : http://had.co.nz/reshape/. , reshape : http://www.ling.upenn.edu/~joseff/rstudy/summer2010_reshape.html

library(reshape)
data$value <- 1
cast(data, ID + Sex + Res ~ Contact, fun = "length")
+12

model.matrix ( , gappy ):

> model.matrix(~ factor(d$Contact) -1)
  factor(d$Contact)ABR factor(d$Contact)CON factor(d$Contact)WIT factor(d$Contact)WWF factor(d$Contact)XYZ
1                    1                    0                    0                    0                    0
2                    0                    1                    0                    0                    0
3                    0                    0                    0                    1                    0
4                    0                    0                    1                    0                    0
5                    0                    1                    0                    0                    0
6                    0                    0                    0                    0                    1
attr(,"assign")
[1] 1 1 1 1 1
attr(,"contrasts")
attr(,"contrasts")$`factor(d$Contact)`
[1] "contr.treatment"
+2