From 03908f43091316375e567b8945ca379ddf670d9e Mon Sep 17 00:00:00 2001 From: ayousry42 Date: Wed, 22 Dec 2021 12:15:50 +0200 Subject: [PATCH 1/2] kmeans --- Data.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Data.R b/Data.R index a7e8307..a2aa6c4 100644 --- a/Data.R +++ b/Data.R @@ -5,7 +5,7 @@ # Loading package #library(ClusterR) -library(cluster) +#library(cluster) #Read spreadsheet file grocery_entries <- read.csv(file.choose()) @@ -38,7 +38,7 @@ plot(sum_ages) #kmeans --Yousri name_total_age<-cbind(grocery_entries[5],grocery_entries[3],grocery_entries[6]) -#x<-readline() +n<-as.numeric(readline("Enter number of clusters")) keameans<-cbind(grocery_entries[3],grocery_entries[6]) -result<-kmeans(keameans,centers = 10) +result<-kmeans(keameans,centers =n) final_result<-cbind(name_total_age,result$cluster) \ No newline at end of file From 3ff44982b86575dd8b3a7465fb787ea0be8aa788 Mon Sep 17 00:00:00 2001 From: Jimmyjr11 Date: Wed, 22 Dec 2021 12:46:03 +0200 Subject: [PATCH 2/2] Summed cities totals --- Data.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Data.R b/Data.R index a2aa6c4..6745ee2 100644 --- a/Data.R +++ b/Data.R @@ -19,8 +19,8 @@ CompCashCredit <- c(sum_cash,sum_credit) barplot(CompCashCredit,names.arg = c('Cash','Credit'),horiz = FALSE,col = c(rgb(0,1,0),rgb(1,0,0))) #City and Total Spent comparison -Jimmy - - +city_total <- cbind(grocery_entries[3], grocery_entries[7]) +sum_cities<-aggregate(total ~city ,city_total,sum)