rcluster-computingk-meansanalysis

Can i do a K-Means cluster analysis based on only one variable (in R)?


I have a dataframe with 2 columns. The first column has the name of a meteorological station and the other column has a corresponding index. Can i do a K-Means cluster analysis in order to group the stations which have a similar index value;

I would like to do this method because the visualization of clustering between stations on a map seems pretty nice.

My dataframe looks like this,

Station  Index 
A   6.3
B   6.8
C   7.2
D   5.6
E   6.1
.
.
.

I know that clustering is an appropriate method for grouping multivariate data. I'm just wondering if this method is also appropriate for only one variable (e.g. index) ?


Solution

  • Yes you can, for example choosing 3 cluster

    cbind(df, cluster = kmeans(df$Index, 3)$cluster)
      Station Index cluster
    1       A   6.3       3
    2       B   6.8       1
    3       C   7.2       1
    4       D   5.6       2
    5       E   6.1       3
    

    Data

    df <- structure(list(Station = c("A", "B", "C", "D", "E"), Index = c(6.3, 
    6.8, 7.2, 5.6, 6.1)), class = "data.frame", row.names = c(NA, 
    -5L))