rm(list=ls()) #清理内存
options(digits=4) #输出结果位数
library(dstatR)
X=c(164,162,186,165,165,187,169,151,157);X
UG=read.csv('UnderGraduate.csv') #大学生个人信息数据
UG
head(UG)
tail(UG)
dim(UG)
names(UG)
summary(UG)
t.test(height~sex,data=UG)
fm=lm(weight~height,data=UG);fm
summary(fm)
plot(weight~height,data=UG);abline(fm) #模型方程
x=c(1,3,5,7,9,2,4,6,8);x
i=1:9;i
j=9:1;j
seq(0.5,9.5,length=20)
df=data.frame(x,i,j);df
UG1=data.frame(g=UG$sex,x=UG$height,y=UG$weight)
head(UG1) #当数据较多时,可用head 显示数据集的前6行,等价于UG[1:6,]
UG2=UG[,c('sex','height','weight')]
head(UG2)
UG3=UG[1:6,1:5]
UG3
Sq.sum <- function(x) {
S=sum(x^2) # S=???x2
S # return(S)
}
Sq.sum <- function(x){ sum(x^2) }
Sq.sum(1:9)
Sq.sum (UG$height)
welcome <- function() print("welcome to use R")
welcome()
welcome <- function(names) print(paste("welcome",names,"to use R"))
welcome("Mr fang")
welcome("Mr Wang")
welcome()
w