#Rounding####
a<-1.06345853240987
a #By default rounds to 6 decimal places
format(round(a, 4)) #Round to 4 decimals
#Print function####
b<-20
print(b)
print(paste("Value of b is:", b)) #paste helps you write a detailed statement
#by default adds an extra space
print(paste0("Value of b is:", b)) #does not add extra space
print(paste("Value of a is:", format(round(a, 4)), "Value of b is:", b))
#printing many things by separating with commas
#Playing with ifelse####
a1<-20
ifelse((a1==20), 20, 40) #Simple ifelse statement for equal-to condition
ifelse((a1!=10), 20, 40) #Not equal to
if(a1==20){print("a is good")
}else{print("a has a problem")}
#You can put any number of commands in the curly brackets
#Check whether pacman is loaded or not####
if(pacman::p_isloaded(pacman)){
p_load(tidyverse) #Load only tidyverse if pacman is loaded
print("All library loaded with pacman")
}else{
pacman::p_load(tidyverse, pacman) #Load both if pacman not loaded
print("Loaded both tidyverse and pacman")
}
#Loops####
i<-1
while(i<6)
{
print(i)
i=i+1
}
city<-c("Mumbai","Kolkata","Paris","Berlin","Munich")
for(i in city){
print(i)
}
#i is assigned locally here
for(i in city){ #Element i in list city
if(i == "Paris"){
break #If Paris is found then break the loop
}
print(i) #Prints only Mumbai and Kolkata
}
#Functions####
dabba<-function(x, y){
print((x+y)/2)
}# Declaring dabba function
class(dabba) #Shows function class
dabba(4,6) #5
dabba(x=4, y=5) #4.5
dabba(x=10, 2) #6
dabba(y=10, x=20) #15
#NPL Data T Test####
#GENDER HAS NO ROLE IN EDUCATION!!!!!!!
p_isinstalled(openxlsx)
install.packages("openxlsx") #installing openxlsx package
p_load(openxlsx) #Plethora of functions for xlsx files
npl <- read.xlsx("npl.xlsx")
View(npl)
glimpse(npl)
str(npl)
npl$Gender <- as.factor(npl$Gender)
npl$Year <- as.factor(npl$Year)
#both Gender and Year should be factors
levels(npl$Year) #9 levels
mscore <- npl%>%filter(Gender == 0)%>%select(Theory, Lab, Total)
View(mscore)
fscore <- npl%>%filter(Gender == 1)%>%select(Theory, Lab, Total)
View(fscore)
#Basic T test####
tscore_lab <- t.test(mscore$Lab, fscore$Lab) #T test for Lab scores
tscore_lab
class(tscore_lab) #htest or hypothesis testing class
names(tscore_lab)
tscore_lab$p.value
#T test for theory marks
tscore_theory <- t.test(mscore$Theory, fscore$Theory)
tscore_theory
#T test for total marks
tscore_total <- t.test(mscore$Total, fscore$Total)
tscore_total
#To be explored further by harsh
tscore_dabba <- t.test(mscore, fscore)
tscore_dabba
#Read up on Sigmoid function
?t.test
#Task:
dabba <- function(pvalue){ #Function to print conclusions based on pvalue
if(pvalue >= 0.05){
print(paste("P value is", round(pvalue, 4),"We can't reject null hypothesis, there is no significant difference between the two groups"))
}else{
print(paste("P value is", round(pvalue, 4),"Reject null hypothesis, it seems there is significant difference"))
}
}
dabba(tscore_lab$p.value)