This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.

Statistic <- c(68, 85, 74, 88, 63, 78, 90, 80, 58, 63)
Math <- c(85, 91, 74, 100, 82, 84, 78, 100, 51, 70)


plot(Statistic, Math,
     main = "統計成績與數學成績之散佈圖",
     xlab = "統計成績",
     ylab = "數學成績",
     pch = 16,           
     col = "darkgreen",  
     cex = 1.5)         
grid()

plot(cars)

Statistic <- c(68, 85, 74, 88, 63, 78, 90, 80, 58, 63)
Math <- c(85, 91, 74, 100, 82, 84, 78, 100, 51, 70)

# 畫出數學成績直方圖
hist(Math,
     main = "數學成績直方圖",
     xlab = "數學成績",
     ylab = "人數",
     col = "lightblue",
     border = "black")

club_type <- c("娛樂休閒", "知識閱讀", "體育競技", "科學創新", "公益活動")
frequency <- c(185, 82, 36, 28, 25)

# 繪製長條圖
barplot(frequency,
        names.arg = club_type,
        main = ,
        xlab = ,
        ylab = ,
        col = "skyblue",
        border = "darkblue")

# 建立資料
club_type <- c("娛樂休閒", "知識閱讀", "體育競技", "科學創新", "公益活動")
frequency <- c(185, 82, 36, 28, 25)

# 加上標籤
labels <- paste(club_type, "(", frequency, ")", sep="")

# 繪製圓餅圖
pie(frequency,
    labels = labels,
    main = "大學生最喜歡參加的社團類型(圓餅圖)",
    col = rainbow(length(frequency)))

# 資料
club_type <- c("娛樂休閒", "知識閱讀", "體育競技", "科學創新", "公益活動")
frequency <- c(185, 82, 36, 28, 25)

# 棒棒糖圖
plot(frequency,
     type = "n",  # 不先畫點
     xaxt = "n",  # 不畫 x 軸
     main = "大學生最喜歡參加的社團類型",
     xlab = "社團類型",
     ylab = "次數",
     ylim = c(0, max(frequency) + 20))

# 畫棒棒糖的線(棒子)
segments(x0 = 1:5, y0 = 0, x1 = 1:5, y1 = frequency, col = "skyblue", lwd = 2)

# 畫棒棒糖的頭(糖果球)
points(1:5, frequency, pch = 16, col = "blue", cex = 2)

# 加上 X 軸標籤
axis(1, at = 1:5, labels = club_type)

data <- read.csv("C:/Users/wenzao/Downloads/table1_1.csv")


if ("Japanese" %in% colnames(data)) {

  stem(data$Japanese)
} else {
  print("找不到 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
data <- read.csv("C:/Users/wenzao/Downloads/table1_1.csv")




names(data)  # 確保有 "Japanese" 欄位
## [1] "Name"       "Statistic"  "Math"       "Japanese"   "Management"
## [6] "Accounting"
japanese <- data$Japanese


mean_jp <- mean(japanese)

# 中位數
median_jp <- median(japanese)


get_mode <- function(x) {
  uniq_vals <- unique(x)
  uniq_vals[which.max(tabulate(match(x, uniq_vals)))]
}
mode_jp <- get_mode(japanese)


sd_jp <- sd(japanese)


var_jp <- var(japanese)


q1_jp <- quantile(japanese, 0.25)


q3_jp <- quantile(japanese, 0.75)


result <- data.frame(
  統計量 = c("平均數", "中位數", "眾數", "標準差", "變異數", "第一四分位數", "第三四分位數"),
  數值 = c(mean_jp, median_jp, mode_jp, sd_jp, var_jp, q1_jp, q3_jp)
)

print(result)
##         統計量      數值
## 1       平均數  67.90000
## 2       中位數  62.00000
## 3         眾數  84.00000
## 4       標準差  16.25115
## 5       變異數 264.10000
## 6 第一四分位數  54.50000
## 7 第三四分位數  82.75000