[R] Help regarding kmeans output. need to save the clusters into different directories/folders.
MacQueen, Don
macqueen1 at llnl.gov
Thu Jan 24 23:14:14 CET 2013
You find the element of clustering_tail that indicates which which point
is in which cluster (the help page for kmeans tells you). Then you use
that element to subset your input data (1.tsv). Then you save each subset
to a separate folder.
By "save to a folder" I would assume you mean write a tsv file, in which
case you use write.table().
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
On 1/23/13 4:41 PM, "Lakshminarayana Motamarri"
<narayana.gupta123 at gmail.com> wrote:
>Hi Team,
>
>I am trying to run kmeans in R, and I need to save the different clusters
>into different folders. How can I achieve this?
>
># this is how my data looks.
>$ *cat 1.tsv | head*
>userid bookid rating bookTotalRatings bookAvgRating
>userTotalRatings userAvgRating
>1 100 0 24 2.7916666666666665 291 2.6735395189003435
>2 200 7 24 2.9583333333333335 6 7.0
>3 300 0 24 1.7916666666666667 874 0.7963386727688787
>4 400 8 24 4.291666666666667 1 8.0
>5 500 5 24 2.4166666666666665 291 2.6735395189003435
>
>$R
>> *input_tail <- read.table("1.tsv", header=FALSE, sep="\t")
>*
>> *clustering_tail <- kmeans(input_tail, 5) *
>
>> *print(clustering_tail)*
>...
>[99973] 4 4 4 4 4 4 4 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
>
>Within cluster sum of squares by cluster:
>[1] 2.731015e+26 8.785281e+22 4.726557e+26 3.513411e+22 5.092071e+25
> (between_SS / total_SS = 98.9 %)
>
>Available components:
>[1] "cluster" "centers" "totss" "withinss"
>"tot.withinss"
>[6] "betweenss" "size"
>
>
>*Now how to I save these 5 clusters into 5 separate folders? *
>
>Please advise,
>Thanks.
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list