Basic Programs | Dataplexa

Basic Programs in R & Beginner Mini Project

This lesson marks the completion of the Beginner Level in the Dataplexa R Programming course. So far, you have learned R basics such as variables, data types, vectors, lists, conditions, loops, and functions.

In this lesson, you will apply everything you have learned by building a complete beginner-level mini project. This project will help you understand how real R programs are structured and executed.


Quick Revision: What You Have Learned

Before starting the mini project, let’s quickly recall the key concepts you already know:

  • Variables and data types
  • Vectors and lists
  • Conditional statements
  • Loops
  • Basic functions

The mini project below will combine all these concepts into one practical example.


📌 Mini Project: Student Marks Analyzer

This beginner mini project is designed to simulate a real-world academic scenario. You will write an R program that analyzes student marks and generates a summary.


🧠 Project Question

Write an R program that:

  • Stores a student’s name
  • Stores marks of multiple subjects
  • Calculates total marks
  • Calculates average marks
  • Determines pass or fail status
  • Displays a clean summary report

Passing rule: If the average score is 50 or above, the student passes. Otherwise, the student fails.


✅ Complete Project Solution

Below is the complete R program that solves the project step by step.

# Student Marks Analyzer - Beginner Mini Project

student_name <- "Alex"

marks <- c(72, 65, 80, 58, 70)

total_marks <- sum(marks)
average_marks <- mean(marks)

result <- if (average_marks >= 50) "PASS" else "FAIL"

cat("----- STUDENT REPORT -----\n")
cat("Student Name:", student_name, "\n")
cat("Marks:", marks, "\n")
cat("Total Marks:", total_marks, "\n")
cat("Average Marks:", average_marks, "\n")
cat("Result:", result, "\n")

🔍 Explanation of the Project

Let’s break down how this program works so that even a beginner can clearly understand it.

1. Storing Student Information

The student’s name is stored in a variable. Marks are stored inside a vector, which allows us to keep multiple values together.

2. Performing Calculations

The sum() function calculates the total marks. The mean() function calculates the average marks.

3. Applying Decision Logic

An if condition checks whether the student has passed or failed based on the average score.

4. Displaying the Output

The cat() function prints a clean, readable report to the console.


✨ Enhanced Version (Optional Improvement)

Below is a slightly improved version that uses a function to make the program reusable.

generate_report <- function(name, marks) {

  total <- sum(marks)
  average <- mean(marks)
  status <- if (average >= 50) "PASS" else "FAIL"

  cat("----- STUDENT REPORT -----\n")
  cat("Name:", name, "\n")
  cat("Total:", total, "\n")
  cat("Average:", average, "\n")
  cat("Status:", status, "\n")
}

generate_report("Alex", c(72, 65, 80, 58, 70))

📝 Practice Exercises


Exercise 1

Modify the project to calculate the highest and lowest marks.

Exercise 2

Change the pass rule so that average marks must be 60 or above.

Exercise 3

Allow the program to handle marks for multiple students.


✅ Practice Answers


Answer 1

max(marks)
min(marks)

Answer 2

status <- if (average_marks >= 60) "PASS" else "FAIL"

Answer 3

students <- list(
  Alex = c(70, 65, 80),
  John = c(45, 50, 60)
)

lapply(students, mean)

🎉 Beginner Level Completed!

Congratulations on completing the Beginner Level of R Programming at Dataplexa. You now have a strong foundation to move into data manipulation, visualization, and analysis.

In the next lesson, you will enter the Intermediate Level and start working with the Apply family of functions.