How to implement clustering on categorical feature vectors in R? I have a dataset like: 

 id color  body  eyes
 1  A  blue  slim green
 2  B black   fat  blue
 3  A black  slim black
 4  C green  slim  blue
 5  D black medim black


whereas each id represents an individual with his individual physical characteristics.

Reproducible:

 structure(list(id = structure(c(1L, 2L, 1L, 3L, 4L), .Label = c("A", 
"B", "C", "D"), class = "factor"), color = structure(c(2L, 1L, 
1L, 3L, 1L), .Label = c("black", "blue", "green"), class = "factor"), 
body = structure(c(3L, 1L, 3L, 3L, 2L), .Label = c("fat", 
"medim", "slim"), class = "factor"), eyes = structure(c(3L, 
2L, 1L, 2L, 1L), .Label = c("black", "blue", "green"), class = "factor")),
 .Names = c("id", 
"color", "body", "eyes"), class = "data.frame", row.names = c(NA, 
-5L))


Then number of the characteristics is fixed (color: blue/black/green, body: slim/fat/medium, eyes: green/blue/black).

My aim is to cluster those individuals.

My conceptual question regards the approach:


A simple correlation could be a first step. A question could be: how the combination of these characteristic is likely to appear in groups of individuals?


A more complicated approach. Maybe k-means clustering. How can address this given that these are categorical variables? should I convert them into dummies?



I'm new to this kind of analysis and any hint/reference to the implementation in R is highly appreciated!
Thanks
You should use dummy variables and then you can toss it directly into K-means. If you have a lot of categories the efficient way to do this is through a one-hot-encoding (sparse-encoding).

Here's a little demo using clustering and then using the clusters in a regression model. In general, you should avoid doing that but it's illuminating in this case.

library(glmnet)
library(Matrix)
n &lt;- 1e5
nclusters &lt;- 5
set.seed(420)
ls &lt;- data.frame(sample(letters, n, replace=TRUE))
xs &lt;- sparse.model.matrix(~.,data=ls)
print(head(xs))  
# Now let's run k-means
out &lt;- kmeans(xs, centers=nclusters)
bs &lt;- rep(1, dim(xs)[2])
# Let's run k-means on the different categories
clusterpred &lt;- data.frame(out[[1]])
ys &lt;- xs %*% bs + rnorm(n)
print(table(clusterpred))
# Now let's use a clustered data set to predict some outcome
cxs &lt;- sparse.model.matrix(~.,data=clusterpred)
model &lt;- glmnet(y=ys, x=xs, alpha=0)
cmodel &lt;- glmnet(y=ys, x=cxs, alpha=0)

# Predictions
yhat &lt;- predict(model, xs)
yhatc &lt;- predict(cmodel, cxs)
# Looking at the difference RMSEs 
print(sqrt( sum( (ys-yhat)**2 )))
print(sqrt( sum( (ys-yhatc)**2 )))