What is .Rmd file?

RMD file which is referred as R Markdown File in long format. This is a plain text document used in data science/analysis and statistics and combines narrative text with executable code written in R. The file uses a .Rmd extension and it allows code execution to automatically generate a report in either HTML, PDF and Word and this aids in data driven decision making.

The Key Difference between ? and ??

? is used to look up the documentation for a particular function or data while ?? is used to perform a broader keyword search across all installed package.When using ? on a function, the package containing the function must be loaded first using the command library() although while using ?? search, the package containing the function only needs to be installed.

Understand the cat function

?cat

The cat() function concatenate and print value strips away data formatting artifacts like quotation marks, row index brackets [1] and gives the value in a human readable format.

Example

Name = "Moses"
Age = 30
cat("My name is" ,Name,"and I am",Age, "years old")
My name is Moses and I am 30 years old

Printing the R version

cat(R.version.string)
R version 4.5.1 (2025-06-13 ucrt)

The R version used in this analysis was cat(R.version.string).This R version was released on June 13th 2025 and thus was preferred since its stability is guaranteed.

Load Libraries

library(tidyverse)
library(tidyr)
library(ggplot2)
library(dplyr)
library(lubridate)
library(readr)
library(readxl)

Import CSV Data

Data <- read_excel("Data.xlsx")


My_First_Recording_Task = read_excel("My First Recording Task.xlsx", 
                                     sheet = "Sheet1")
View(My_First_Recording_Task)

Check the structure of data

cat(str(Data), sep = "\n")
tibble [50 × 11] (S3: tbl_df/tbl/data.frame)
 $ Name              : chr [1:50] "Brian Otieno" "Grace Wanjiku" "Kevin Mwangi" "Faith Achieng" ...
 $ Final Exam        : num [1:50] 72 85 52 90 42 76 48 92 67 40 ...
 $ Age               : num [1:50] 19 20 18 21 19 20 22 18 21 19 ...
 $ Mid-Term          : num [1:50] 65 78 45 82 38 70 55 88 60 35 ...
 $ Attendance (%)    : num [1:50] 85 92 67 100 74 58 95 80 43 89 ...
 $ Study Hours       : num [1:50] 185 120 280 75 350 190 25 410 165 95 ...
 $ Outcome           : num [1:50] 1 1 1 1 0 1 0 1 1 0 ...
 $ Stream            : chr [1:50] "Science" "Arts" "Science" "Commerce" ...
 $ Year              : num [1:50] 2024 2025 2024 2025 2024 ...
 $ Stardardized Score: num [1:50] 82 95 62 100 52 86 58 102 77 50 ...
 $ Study Year        : num [1:50] 4 4 2 3 7 7 7 4 7 2 ...

Convert Data to a DF

Data <- as.data.frame(Data)

Check data type after conversion

cat(class(Data))
data.frame

Understanding the ggplot function

?ggplot2

Example 1

ggplot(My_First_Recording_Task, aes(x = Stream, fill = Stream))+
  geom_bar()+
  geom_text(stat = "count",
            aes(label = after_stat(
              paste0(round(count/sum(count)*100,1),"%")
            )),
            vjust = -0.5
            ) +
  ggtitle("Histogram plot of the variable student Stream",
          subtitle = "Analysis of data from 50 students")+
  theme_minimal()+
  theme(plot.title = element_text(hjust = 0.5),
        plot.subtitle = element_text(hjust = 0.5),
        panel.grid = element_blank())+
  scale_y_continuous(
    expand = expansion(mult = c(0, 0.5))
  )

Example 2

ggplot(My_First_Recording_Task, aes(x = Outcome, fill = Outcome)) +
  geom_bar() +
  geom_text(stat = "count",
            aes(label = after_stat(paste0(round(count/sum(count)*100, 1), "%")
                                   )),
            vjust = -0.5
            ) +
  ggtitle("Histogram plot of the variable students Performance",
          subtitle = "Analysis of 50 students") +
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.5),
        plot.subtitle = element_text(hjust = 0.5),
        panel.grid = element_blank())+
  scale_y_continuous(
    expand = expansion(mult = c(0, 0.5))
    )

The short cut to insert a code chunk is to use Ctr+Alt+I in windows machines and Cmd+Options+I.

Change variable type of variable Stream

Data$Stream = as.factor(Data$Stream)

Check the class of the variable after conversion

cat(class(Data$Stream))
factor

Free Data Sources

Note that you must have an existing Kaggle account to download data

Load the R Commander

R Commander is normally loaded by executing the command library(Rcmdr).

#library(Rcmdr)

Data understanding

Students were interviewed while collecting data. Out of the students interviewed, a total of 50 students were randomly selected and information they provided was selected to form the data for the analysis. The data contained 50 rows and 11. The columns in the data was selected based on the association with the question under investigation Name, Final Exam, Age, Mid-Term, Attendance (%), Study Hours, Outcome, Stream, Year, Stardardized Score, Study Year.

Example

cat(colnames(Data), sep = "\n")
Name
Final Exam
Age
Mid-Term
Attendance (%)
Study Hours
Outcome
Stream
Year
Stardardized Score
Study Year