cars <- read.table('http://www.win-vector.com/dfiles/car.data.csv',header=TRUE,sep=',')
print(head(cars))
##   buying maint doors persons lug_boot safety rating
## 1  vhigh vhigh     2       2    small    low  unacc
## 2  vhigh vhigh     2       2    small    med  unacc
## 3  vhigh vhigh     2       2    small   high  unacc
## 4  vhigh vhigh     2       2      med    low  unacc
## 5  vhigh vhigh     2       2      med    med  unacc
## 6  vhigh vhigh     2       2      med   high  unacc
with(cars,table(safety,rating))
##       rating
## safety acc good unacc vgood
##   high 204   30   277    65
##   low    0    0   576     0
##   med  180   39   357     0
print(summary(cars$safety))
## high  low  med 
##  576  576  576
m <- model.matrix(~0+safety,data=cars)
print(head(m))
##   safetyhigh safetylow safetymed
## 1          0         1         0
## 2          0         0         1
## 3          1         0         0
## 4          0         1         0
## 5          0         0         1
## 6          1         0         0