### Practicals #2
#Task 1
people<-read.csv2("01_data.csv")
people<-people[,1:3]# Removal of unnecessary empty columns
summary(people)

mean(people$height)
# [1] 179.2391
var(people$height)
# [1] 81.36067

means.agg<-aggregate(people$height, list(people$eye.color, people$sex),
          mean)
names(means.agg)<-names(people)#Renaming the column names in aggregated data
means.agg
#   eye.color sex   height
# 1      blue   F 173.5000
# 2     brown   F 175.8571
# 3      blue   M 180.3333
# 4     brown   M 185.9167

var.agg<-aggregate(people$height, list(people$eye.color, people$sex),
          var)
names(var.agg)<-c(names(people)[1:2], "height.variance")#Renaming the column names in aggregated data
var.agg
#   eye.color sex height.variance
# 1      blue   F       113.66667
# 2     brown   F        53.14286
# 3      blue   M        54.66667
# 4     brown   M        74.04167

sqrt(var.agg$height.variance) #Standard deviations
# [1] 10.661457  7.289915  7.393691  8.604747

install.packages("sciplot")#Installing package sciplot which contains the se function
library(sciplot)#loading the sciplot package

se.agg<-aggregate(people$height, list(people$eye.color, people$sex),
          se)
#   Group.1 Group.2        x
# 1    blue       F 5.330729
# 2   brown       F 2.755329
# 3    blue       M 3.018462
# 4   brown       M 3.512873


# Task 2

sam<-rnorm(10, mean=25.5, sd=2.4)
mean(sam)
# [1] 26.07251

se(sam)
# [1] 0.7254653

sam[4]<-sam[4]*10 #Multiplication of the fourth number in vector sam by 10

mean(sam)
# [1] 47.60238

se(sam)
# [1] 21.30195

median(sam)
# [1] 26.06293
sam[4]<-sam[4]/10 #Generating the original sam vector
median(sam)
# [1] 25.90455


sam<-rnorm(100, mean=25.5, sd=2.4)
mean(sam)
# [1] 25.74904

se(sam)
# [1] 0.233132

sam[4]<-sam[4]*10
mean(sam)

### Task A and B
pnorm(100, 81, 9, lower.tail = F)
# 0.01738138

pnorm(50, 81, 9, lower.tail = T)
# [1] 0.0002861171

# Tasks CDEF
#C
qnorm(0.05, 179, 11, lower.tail=F)
# 197.0934

#D
qnorm(0.05, 179, 11, lower.tail=T)
# 160.9066

#E
pnorm(200, 179, 11, lower.tail = F)*550
# [1] 15.46885

#F
1-pnorm(170,179, 11,lower.tail = T)-pnorm(190,179, 11,lower.tail = F)
# [1] 0.6347181
