Sunteți pe pagina 1din 3

Risk Management Quantative Techniques

library(XLConnect)

locat<-"Data.xlsx"

datap<-as.matrix.data.frame(readNamedRegionFromFile(locat,"data",FALSE))

datao <- matrix(, nrow = 20, ncol = 20)

for(j in 1:20)

for(i in 1:400)

datao[i][j]<

return <- matrix(, nrow = 19, ncol = 20)

for(j in 20:1)

for(i in 20:2 )

return[i-1][j]<-(datap[i-1][j]-datap[i][j])/datap[i][j]

# Reading data into lists #

sheet<-list()

sheet[[1]]<-read.csv("Data1.csv")

sheet[[2]]<-read.csv("Data2.csv")

# Handling missing values in Data2.csv #

for(i in 1:length(sheet[[2]])){

for(j in 1:length(sheet[[2]][[i]])){

if(is.na(sheet[[2]][[i]][j])==T){

cat(sprintf("Positions of missing values in Data2.csv:Student id %s,Subject no. %s\n", j,i))

#sheet[[2]][[i]][j]=sheet[[1]][[i]][j]
}

# Calculating mean,variance,standard deviation (subject wise for both table1 & table2) #

Mean.list<-list()

Mean<-c()

for(i in 1:2){

for(j in 2:length(sheet[[i]])){

cat(sprintf("mean marks of sub no.%s in table no.%s is %s\n", j-1,i,mean(sheet[[i]][[j]],na.rm=TRUE)))

cat(sprintf("variance of marks of sub no.%s in table no.%s is %s\n", j-


1,i,var(sheet[[i]][[j]],na.rm=TRUE)))

cat(sprintf("Standard deviation of marks of sub no.%s in table no.%s is %s\n", j-


1,i,sd(sheet[[i]][[j]],na.rm=TRUE)))

Mean[j-1]<-mean(sheet[[i]][[j]],na.rm=TRUE)

Mean.list[[i]]<-Mean

# Calculating mean,variance,standard deviation (for each student in both table1 & table2) #

for(i in 1:2){

for(j in 1:25){

cat(sprintf("mean marks of student %s in table no.%s is %s\n",


j,i,mean(as.numeric(sheet[[i]][j,2:11]),na.rm=TRUE)))

cat(sprintf("variance of marks of student %s in table no.%s is %s\n",


j,i,var(as.numeric(sheet[[i]][j,2:11]),na.rm=TRUE)))

cat(sprintf("Standard deviatin of marks of student %s in table no.%s is %s\n",


j,i,sd(as.numeric(sheet[[i]][j,2:11]),na.rm=TRUE)))

}
# Median of subject-wise mean values #

for(i in 1:2){

cat(sprintf("median of means of subjects in table no.%s is:%s\n",i,median(Mean.list[[i]])))

# Reading req. inputs to read and print marks in particular subject of particular student id #

readinput <- function()

x <- readline(prompt="Enter table no: ")

y <- readline(prompt="Enter Studentid: ")

z <- readline(prompt="Enter Sub no: ")

x <-as.integer(x)

y <-as.integer(y)

z <-as.integer(z)

sprintf("Marks of student %s in subject no.%s is:%s", y,z,sheet[[x]][[z+1]][y])

readinput()

S-ar putea să vă placă și