Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.4 kB
2
Indexable
Never
setwd("C:/Users/ASUS PC/OneDrive/Tài liệu/XSTK/THXSTK/bai6")

#bai1
x =c(1,2,5,7,-3,0,5,1,5,6)
y=c(2,2,0,-5,7,8,11,9,3,2)
#cau a
x+y
x*y
x-y
#cau b
z=x[x%%2==0]
t=y[y%%2!=0]
#cau c
x[x>0]
y[y>0]
#cau d
#trung binh
mean(x)
mean(y)
#do lech chuan
sd(x)
sd(y)
#sai so chuan



#cau e
max(x)
min(x)
max(y)
min(y)
#cau f
sort(x,decreasing = F)
sort(y,decreasing = T)
#cau g
save(x,file="x.rda")
save(y,file="y.rda")


#bai 2
#cau a
data1=read.csv("data01.csv",header = T)
mean(data1$FPSA)
var(data1$FPSA)
median(data1$FPSA)
mean(data1$TPSA)
var(data1$TPSA)
median(data1$TPSA)
#cau b
plot(1:length(data1$FPSA),data1$FPSA,type="l")
plot(1:length(data1$TPSA),data1$TPSA,type="l")
boxplot(data1$FPSA)
boxplot(data1$TPSA)
#cau c
data1$FPSA[data1$K==0]
data1$FPSA[data1$K==1]
#cau d
data2=read.csv("data02.csv",header=T)
merge(data1,data2,by="K")
#cau e
tpsa= rep(0,length(data1$Age))
for(i in 1:length(data1$Age))
{
  if(data1$Age[i]<=30) tpsa[i]=0
  else if(data1$Age[i]<=50) tpsa[i]=1
  else tpsa[i]=2
}
print(tpsa)

#bai 3
#cau a
#cach 1
sinhvien=1:10
cauhoi1=c(3,3,3,4,3,4,3,4,3,4)
cauhoi2=c(5,3,5,5,2,2,5,5,4,2)
cauhoi3=c(1,3,1,1,1,3,1,1,1,1)
data3_c1=data.frame(sinhvien,cauhoi1,cauhoi2,cauhoi3)
#cach 2

#cach 3
data3_c3=read.table("bai3.txt",header = T)
#cach 4
data3_c4=edit(data.frame())

#cau b
ch1=data3_c1$cauhoi1
ch2=data3_c1$cauhoi2

#cau c
mt=rbind(cauhoi1,cauhoi2)
mt=rbind(mt,cauhoi3)
barplot(mt,col=c("red","green","blue"),names.arg = sinhvien)

#cau d
barplot(rbind(cauhoi2,cauhoi3),col=c("red","green"),horiz=T,names.arg = sinhvien)
legend("topright",c("cauhoi2","cauhoi3"),fill=c("red","green"))


#bai4
#cau a
X=rbinom(100,size=60,prob=0.4)
hist(X,breaks=10)
#cau b
Y=rpois(100,4)
hist(Y,breaks=10)
#cau c
Z=rnorm(100,50,4)
curve(dnorm(x,50,4),from=30,to=70)
curve(pnorm(x,50,4),from = 30,to=70)
#cau d
W=rexp(100,1/25)
curve(dexp(x,1/25),from=0,to=200)
curve(pexp(x,1/25),from=0,to=200)



#BAI 6
#cau a
data6=edit(data.frame())
#cau b
barplot(data6$snow.cover,names.arg = data6$year,xlab="year",ylab="snow.cover",col="green")
# cau c
hist(data6$snow.cover,breaks=20)
#cau d



#BAI 7
data7=edit(data.frame())
barplot(data7$totalincident,names.arg =data7$temperature,xlab="temperature(F)"
        ,ylab="total incidents",col="yellow")


#BAI 8
#cau a
#cach 1
Nam=1960:1980
US =c(1.5,1.1,1.1,1.2,1.4,1.6,2.8,2.8,4.2,5,5.9,4.3,3.6,6.2,10.9,9.2,5.8,6.4,7.6,11.4,13.6)
Anh=c(1,3.4,4.5,2.5,3.9,4.6,3.7,2.4,4.8,5.2,6.5,9.5,6.8,8.4,16,24.2,16.5,15.9,8.3,13.4,18)
Nhat=c(3.6,5.4,6.7,7.7,3.9,6.5,6,4,5.5,5.1,7.6,6.3,4.9,12,24.6,11.7,9.3,8.1,3.8,3.6,8)
Duc=c(1.5,2.3,4.5,3,2.3,3.4,3.5,1.5,18,2.6,3.7,5.3,5.4,7,7,5.9,4.5,3.7,2.7,4.1,5.5)
lamphat1=data.frame(Nam,US,Anh)
lamphat2=data.frame(Nam,Nhat,Duc)
#cau b
lamphat=merge(lamphat1,lamphat2,by="Nam")
#cau c
length(lamphat$US[lamphat$US>5])
length(lamphat$Anh[lamphat$Anh>5])
length(lamphat$Nhat[lamphat$Nhat>5])
length(lamphat$Duc[lamphat$Duc>5])
#cau d
hist(lamphat$US,breaks= 10)
hist(lamphat$Anh,breaks=10)
hist(lamphat$Nhat,breaks=10)
hist(lamphat$Duc,breaks=10)
#cau e
summary(lamphat$US)
summary(lamphat$Anh)
summary(lamphat$Nhat)
summary(lamphat$Duc)
#cau f: chac la du vao phuong sai hoac do lech chuan
#cau g:
lamphat1=data.frame(Nam=1960:1979,US=lamphat$US[lamphat$Nam!=1980],Anh=lamphat$Anh[lamphat$Nam!=1980]
                    ,Nhat=lamphat$Nhat[lamphat$Nam!=1980],Duc=lamphat$Duc[lamphat$Nam!=1980])