How to take the index of the nearest centroid as a feature? To create additional features for a dataset I have conducted a cluster analysis and assigned a feature to a data set for cluster membership:
# Determine number of clusters
wss <- (nrow(train.n)-1)*sum(apply(train.n[,2:74],2,var))
for (i in 2:74) wss[i] <- sum(kmeans(train.n[,2:74],
                                     centers=i)$withinss)
plot(1:74, wss, type="b", xlab="Number of Clusters",
     ylab="Within groups sum of squares")

# K-Means Cluster Analysis
# append cluster assignment
fit   <- kmeans(train.n, 6)
train <- data.frame(train, fit$cluster)
    fit   <- kmeans(test.n, 6)
    test  <- data.frame(test, fit2$cluster)

But this presentation from Berkeley suggests to use "the index of the nearest centroid" as a feature. I'm a little unclear on this. 
Could someone explain how this is different and give an example, either based on my example R code or in another language?
 A: It's difficult to interpret the author's intent from slides, but I would generally interpret the cluster membership described as a categorical variable.
From the docs, it appears that kmeans$cluster has integers corresponding to cluster. You're right that this is interpretable as an index, but many software implementations of learning algorithms will treat this as a numeric value by default. Some, like the example below, require transforming them into several boolean variables. 
In this case, each boolean would describe whether the datum is nearest to a particular cluster. (I believe R—or at least some packages—has a means of treating integer columns as categories, but I don't use it enough to speak with authority.)
Here's an example in python using the iris dataset and sklearn:
import numpy as np, sklearn
from sklearn import datasets, preprocessing
from sklearn.cluster import KMeans
iris = datasets.load_iris()
X = iris.data
y = iris.target
kmeans = KMeans(n_clusters=3)
clusters = np.argmin(kmeans.fit_transform(X), axis = 1) # fit_transform transforms X into cluster distance space; argmin is the cluster with minimum distance
print clusters
enc = preprocessing.OneHotEncoder(sparse=False)
clustersAsBoolean = enc.fit_transform(clusters.reshape(-1,1))
print clustersAsBoolean

The first print statement will show recognizable cluster indices:
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 1 1 1 1 2 1 1 1 1 1 1 2 2 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 1 1 1 2 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 2]

The second (shortened):
array([[ 1.,  0.,  0.],
     [ 1.,  0.,  0.],
     [ 1.,  0.,  0.],
     [ 1.,  0.,  0.],
     [ 1.,  0.,  0.],
     [ 1.,  0.,  0.],
     [ 1.,  0.,  0.],
     [ 1.,  0.,  0.],
     [ 1.,  0.,  0.],
     [ 1.,  0.,  0.],
     [ 1.,  0.,  0.] 
     ...
     [ 0.,  1.,  0.],
     [ 0.,  1.,  0.],
     [ 0.,  0.,  1.]])

