title: “Midtern” author: “Hayato” date: “2025-04-16” output:
html_document
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
japanese <- c(84,63,61,49,89,51,59,53,79,91)
stem(japanese)
##
## The decimal point is 1 digit(s) to the right of the |
##
## 4 | 9
## 5 | 139
## 6 | 13
## 7 | 9
## 8 | 49
## 9 | 1
# 資料
japanese <- c(84, 63, 61, 49, 89, 51, 59, 53, 79, 91)
# 1. 平均數
mean_j <- mean(japanese)
# 2. 中位數
median_j <- median(japanese)
# 3. 眾數函數
get_mode <- function(x) {
ux <- unique(x)
tab <- tabulate(match(x, ux))
modes <- ux[tab == max(tab)]
return(modes)
}
mode_j <- get_mode(japanese)
# 4. 標準差
sd_j <- sd(japanese)
# 5. 變異數
var_j <- var(japanese)
# 6. 第一四分位數 Q1
q1_j <- quantile(japanese, 0.25)
# 7. 第三四分位數 Q3
q3_j <- quantile(japanese, 0.75)
# 顯示結果
cat("Mean:", mean_j, "\n")
## Mean: 67.9
cat("Median:", median_j, "\n")
## Median: 62
cat("Mode(s):", mode_j, "\n")
## Mode(s): 84 63 61 49 89 51 59 53 79 91
cat("Standard Deviation:", sd_j, "\n")
## Standard Deviation: 16.25115
cat("Variance:", var_j, "\n")
## Variance: 264.1
cat("Q1 (1st Quartile):", q1_j, "\n")
## Q1 (1st Quartile): 54.5
cat("Q3 (3rd Quartile):", q3_j, "\n")
## Q3 (3rd Quartile): 82.75