I am working on the project that requires data mining. I have been asked to use R. I have a dataset with all categorical variables and would like to form clusters on that. I am unable to figure out how to do so in R.

Here is what I have done: I have converted all the variables to "factor" data type in R. But I am not able to see the underlying numbered levels. I also do not know how to use this with kmeans() to get the required result.

My question is how do I form clusters on these factors.

Here is what the data looks like:

RowNum|EmpNum|EmpName|EmpOrganization|EmpTitle|EmpLeaderNumber|EmpDepartment|EmpAccesstoApplicaton|EmpAccessID The entire data is 14MB.

The effort is to cluster people with similar access. So people with similar Title or in similar org might have similar access. I understand kmeans() isn't the best option, but that is what I would like to use for the first draft.

I converted the EmpOrganization, EmpTitle etc to numeric data in excel using simple vlookup. It is easy to convert these to indicator variables using if statement in excel but I'm hoping that there is a more efficient way to do this in R itself.

  • $\begingroup$ Can you show the code you do have? $\endgroup$ – doctorlove Aug 19 '14 at 17:50
  • $\begingroup$ Surely something like fit <- kmeans(mydata, 5) for 4 clusters works? See statmethods.net/advstats/cluster.html $\endgroup$ – doctorlove Aug 19 '14 at 17:55
  • 2
    $\begingroup$ Do you just not know how to do this in R? Or do you not know how to do this in any language? If you want suggestions for methods on clustering categorical data, you're better off asking at Cross Validated; that is not a specific programming question. $\endgroup$ – MrFlick Aug 19 '14 at 18:12
  • $\begingroup$ you have to specify what the required result is. is there any relationship between the categorical variables (eg hierarchies). what should the clusters represent? do you want to identify groups of roughly equal frequency, or do you actually have a supervised learning problem, where you want to find 'clusters' that have the similar effect ( in which case you are better off with a tree building package such as rpart) $\endgroup$ – seanv507 Aug 20 '14 at 7:47
  • 1
    $\begingroup$ Are the categories ordinal or nominal? $\endgroup$ – Glen_b Aug 20 '14 at 7:55

In R cluster package you can use daisy, this will give you a dissimilarity matrix it works for mixed types also. Then you can use any other clustering function directly.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.