How to do it...

Perform the following steps to cluster customer data into a hierarchy of clusters:

  1. First, you need to load data from customer.csv and save it into customer:
    > customer= read.csv('customer.csv', header=TRUE)
    > head(customer)
    Output
      ID Visit.Time Average.Expense Sex Age
    1  1          3             5.7   0  10
    2  2          5            14.5   0  27
    3  3         16            33.5   0  32
    4  4          5            15.9   0  30
    5  5         16            24.9   0  23
    6  6          3            12.0   0  15 
  1. You can then examine the dataset structure:
        > str(customer)
        Output
        'data.frame':  60 obs. of  5 variables:
         $ ID             : int  1 2 3 4 5 6 7 8 9 10 ...
         $ Visit.Time     : int  3 5 16 5 16 3 12 14 6 3 ...
         $ Average.Expense: num  5.7 14.5 33.5 15.9 24.9 12 28.5 18.8          23.8 5.3 ...
         $ Sex            : int  0 0 0 0 0 0 0 0 0 0 ...
         $ Age            : int  10 27 32 30 23 15 33 27 16 11 ...  
  1. Next, you should ...

Get Machine Learning with R Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.