data <- read.csv("C:/Users/Ngo Trang/Documents/Supermarket Transactions.csv", header = TRUE)
names(data)
## [1] "X" "PurchaseDate" "CustomerID"
## [4] "Gender" "MaritalStatus" "Homeowner"
## [7] "Children" "AnnualIncome" "City"
## [10] "StateorProvince" "Country" "ProductFamily"
## [13] "ProductDepartment" "ProductCategory" "UnitsSold"
## [16] "Revenue"
bdt <- c("Gender","MaritalStatus","Homeowner", "City","StateorProvince", "Country","ProductFamily","ProductDepartment", "ProductCategory")
d <- data[ ,bdt]
ntt1 <- table(data$Country)
ntt1
##
## Canada Mexico USA
## 809 3688 9562
Vậy trong bộ dữ liệu này có 809 người ở Canada.
Vậy trong bộ dữ liệu này có 3688 người ở Mexico.
Vậy trong bộ dữ liệu này có 9562 người ở USA.
ntt2 <- table(data$Country)/sum(nrow(data))
ntt2
##
## Canada Mexico USA
## 0.05754321 0.26232307 0.68013372
Vậy trong bộ dữ liệu này có 5.7543211 % người ở Canada.
Vậy trong bộ dữ liệu này có 26.2323067 % người ở Mexico.
Vậy trong bộ dữ liệu này có 68.0133722 % người ở USA.
text(barplot(ntt1, col = c("blue", "green", "red"),
main = "Biểu đồ cột: Country",
xlab = "quốc gia", ylab = "Tần số"),
ntt1, labels = ntt1, pos = 1)
names(ntt2)
## [1] "Canada" "Mexico" "USA"
pie(ntt2,
col = c("blue", "green","red"),
main = "Pie chart with percentages",
labels = ntt2)
legend("topright",
legend = names(ntt2),
fill = c("blue", "green", "red"),
title = "Countries")