a) Creation of dataframe and addition of two rows and a “Income”
column with numerical values
exam_score = data.frame(
ID = c(1, 2, 3, 4, 5),
Name = c("Alice", "Bob", "David", "John", "Jenny"),
Age = c(20, 25, 30, 22, 18),
Score = c(100, 78, 90, 55, 81)
)
print(exam_score)
new_row1 = c(6, "Magnus", 25, 99)
new_row2 = c(7, "Hikaru", 24, 96)
Income= c(4500, 4800, 6200, 6500, 7100, 9900, 8500)
exam_score_new = rbind(exam_score, new_row1, new_row2) # addition of 2 rows
exam_score_ext = cbind(exam_score_new, Income) # addition of a column
print(exam_score_ext)
exam_score_ext$Age= as.numeric(exam_score_ext$Age) # conversion into numerical values
exam_score_ext$Score= as.numeric(exam_score_ext$Score)
exam_score_ext$Income= as.numeric(exam_score_ext$Income)
print(exam_score_ext)
b) Arithmetic Operation in Age, Score and Income Column
cat("Max Value of Age", "is",max(exam_score_ext$Age), "\n")
cat("Min Value of Age", "is",min(exam_score_ext$Age), "\n")
cat("Median Value of Age", "is",median(exam_score_ext$Age), "\n")
cat("Summation of Age", "is",sum(exam_score_ext$Age), "\n")
cat("Mean Value of Age", "is",mean(exam_score_ext$Age), "\n")
cat("Standard deviation of Age", "is", sd(exam_score_ext$Age), "\n")
cat("Variance of Age", "is",var(exam_score_ext$Age), "\n")
cat("Quantile Value of Age", "is", quantile(exam_score_ext$Age), "\n", "\n", "\n")
cat("Max Value of Score", "is",max(exam_score_ext$Score), "\n")
cat("Min Value of Score", "is",min(exam_score_ext$Score), "\n")
cat("Median Value of Score", "is",median(exam_score_ext$Score), "\n")
cat("Summation of Score", "is",sum(exam_score_ext$Score), "\n")
cat("Mean Value of Score", "is",mean(exam_score_ext$Score), "\n")
cat("Standard deviation of Score", "is", sd(exam_score_ext$Score), "\n")
cat("Variance of Score", "is",var(exam_score_ext$Score), "\n")
cat("Quantile Value of Score", "is", quantile(exam_score_ext$Score), "\n", "\n", "\n")
cat("Max Value of Income", "is",max(exam_score_ext$Income), "\n")
cat("Min Value of Income", "is",min(exam_score_ext$Income), "\n")
cat("Median Value of Income", "is",median(exam_score_ext$Income), "\n")
cat("Summation of Income", "is",sum(exam_score_ext$Income), "\n")
cat("Mean Value of Income", "is",mean(exam_score_ext$Income), "\n")
cat("Standard deviation of Income", "is", sd(exam_score_ext$Income), "\n")
cat("Variance of Income", "is",var(exam_score_ext$Income), "\n")
cat("Quantile Value of Income", "is", quantile(exam_score_ext$Income), "\n")
b) Arithmetic Operation in Age, Score and Income Column using
loop
Here, Column 1,2 and 3 denote Age, Score and Income
respectively
x= data.frame(exam_score_ext$Age, exam_score_ext$Score, exam_score_ext$Income)
print(x)
for(i in 1:3){
cat("Max of column",i, "is",max(x[1:7,i]), "\n")
cat("Min of column",i, "is",min(x[1:7,i]), "\n")
cat("Median of column",i, "is",median(x[1:7,i]), "\n")
cat("Sum of column",i, "is",sum(x[1:7,i]), "\n")
cat("Mean of column",i, "is",mean(x[1:7,i]), "\n")
cat("Standard deviation of column",i, "is",sd(x[1:7,i]), "\n")
cat("Variance of column",i, "is",var(x[1:7,i]), "\n")
cat("Quantiles of column",i, "is",quantile(x[1:7,i]), "\n","\n","\n")
}
c) Finding Correlation among Age, Score and Income
cat("Correlation between Age and Score is",cor(exam_score_ext$Age, exam_score_ext$Score), "\n", "\n")
cat("Correlation between Age and Income is",cor(exam_score_ext$Age, exam_score_ext$Income), "\n", "\n")
cat("Correlation between Score and Income is",cor(exam_score_ext$Score, exam_score_ext$Income), "\n", "\n")