R Programming/Clustering

K-Means Clustering
You can use the  function.

First create some data:

To apply, you need to specify the number of clusters:

Hierarchical Clustering
The basic hierarchical clustering function is, which works on a dissimilarity structure as produced by the   function:

The resulting tree can be cut using the  function.

Cutting it at a given height: Cutting it to obtain given number of clusters:

Available alternatives

 * See packages class, amap and cluster
 * See The R bioinformatic page on clustering