Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Create a student file (either .csv/.xlsx) that contains:
- #Student Number
- #Course (BSCS, BSIS, and BSIT only)
- #Year
- #Section
- #Create unsorted 50 records of student.
- #Analyze the records according to the courses, year and section. #Present the data in a graph.
- #Determine how many students per course (pie graph)
- #Determine how many students per year level in the course (line graph) #Determine how many students per section in every year level and course (bar graph)
- library("readxl")
- library("writexl")
- courses <- c("BSCS", "BSIS", "BSIT")
- #courses is for reference only. could be used if decided.
- stud_data<-function(){
- studnum <- c()
- studname <- c()
- studcourse <- c()
- studyr <- c()
- section <- c()
- #requirement is up to 50 students only
- i<-1
- max <- 50
- cont<-'exit'
- roww<-0
- while(cont!="n"||cont!="N"){
- if(file.exists("StudentRecord.xlsx")==TRUE){
- dt<-read_excel("StudentRecord.xlsx")
- items<-nrow(dt)
- roww=items
- print(paste("Record(s) : ",items))
- if(items==50){print("Record Full!");print("Only accepts 50 records");
- print("remove some data to continue...");
- break}
- }
- #check the number of students inside file
- snum <- readline(prompt=("STUDENT NUMBER > ")); print("________________")
- sname <- readline(prompt=("STUDENT NAME >")); print("________________")
- scourse <- readline(prompt=("[BSCS/BSIS/BSIT] COURSE >")); print("________________")
- syr <- readline(prompt=("YEAR >")); print("________________")
- sect <- readline(prompt=("SECTION >")); print("________________")
- studnum[i]=snum
- studname[i]=sname
- studcourse[i]=scourse
- studyr[i]=syr
- section[i]=sect
- print("=========================================")
- cont = readline(prompt=("Save Input? [y/n] >"))
- if(cont=='y'||cont=='Y'){ i<- i+1
- stud_data=data.frame(
- StudentNumber=c(studnum),
- StudentName=c(studname),
- StudentCourse=c(studcourse),
- StudentYear=c(studyr),
- Sections=c(section)
- )
- if(file.exists("StudentRecord.xlsx")==FALSE&&roww==0){
- write_xlsx(stud_data,"StudentRecord.xlsx", col_names = TRUE)
- }
- else{
- write_xlsx(stud_data,"Temporary.xlsx", col_names = TRUE)
- dt1<-read_excel("Temporary.xlsx")
- dt2<-read_excel("StudentRecord.xlsx")
- dtm<-merge(dt1,dt2, all.x=TRUE, all.y=TRUE)
- write_xlsx(dtm,"StudentRecord.xlsx")
- file.remove("Temporary.xlsx")
- }
- cont=readline(prompt=("Input Again? [y/n] >"))
- if(cont=='n'||cont=='N'){break;}
- }
- else if(cont=='N'||cont=='n'){
- cont=readline(prompt=("Input Again? [y/n] >"))
- if(cont=='n'||cont=='N'){break;}
- }
- else if((cont!='y'|cont!='Y')&&(cont!='N'|cont!='n'))
- { print("Invalid Input.");}
- }
- }
- mn<-function(){
- #x=stud_data()
- #^call only stud_data for inputting records
- if(file.exists("StudentRecord.xlsx")==TRUE){
- dt<-read_excel("StudentRecord.xlsx")
- s1<-sum(dt$StudentCourse=="BSIT")
- s2<-sum(dt$StudentCourse=="BSIS")
- s3<-sum(dt$StudentCourse=="BSCS")
- s1<-paste("BSIT = ",s1)
- s2<-paste("BSIS = ",s2)
- s3<-paste("BSCS = ",s3)
- lbl<-c(s1,s2,s3)
- vals<-as.numeric(gsub("[^[:digit:]]","",lbl))
- names(vals)<-seq_along(vals)
- lbl<-lbl[as.numeric(names(sort(vals, decreasing=TRUE)))]
- pie(table(dt$StudentCourse), main="Number of Students per Course", col=rainbow(3),clockwise=TRUE)
- legend("bottomright",lbl)
- #displaying students per course pie chart
- graphics.off()
- require(ggplot2)
- library(ggplot2)
- ggplot(data=dt,aes(x=StudentYear,y=StudentCourse))+geom_line(group=1)+geom_count()
- }
- }
- mn()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement