weight <- c(50,55,63,55,67,43,52)
high <- c(150,160,170,175,150,153,165)
mean(weight) #平均數
## [1] 55
median(weight) #中位數
## [1] 55
as.numeric(names(table(weight)))[which.max(table(weight))] #眾數
## [1] 55
sd(weight) #standard deviation
## [1] 8.020806
var(weight) #variance
## [1] 64.33333
#四分位:把資料切分為四等分,中間的三條線就是四分位,Q1=P25,Q2=P50,Q3=75
Q1 <- quantile(weight, 1 / 4)
Q2 <- quantile(weight, 2 / 4)
Q3 <- quantile(weight, 3 / 4)
P1 <- quantile(weight, 1 / 10)
P2 <- quantile(weight, 2 / 10)
P3 <- quantile(weight, 3 / 10)
P5 <- quantile(weight, 5 / 10)
P5
## 50%
## 55
Q2
## 50%
## 55
median(weight)
## [1] 55
# Load ggplot2
library(ggplot2)
# Load ggplot2
library(ggplot2)
# Create data
data <- data.frame(
name=c("王曉明","B","C","D","E","F") ,
value=c(50,55,63,55,67,43)
)
# Barplot
ggplot(data, aes(x=name, y=value)) +
geom_bar(stat = "identity", width=0.2, fill="skyblue")

plot(weight,high)

plot(weight,high,
pch=17,
col="orange",
xlab="體重",
ylab="身高",
main="班級的身高體重")
