LNCT University, Bhopal
Department of Computer Applications
Course: R Programming for Data Science and Data Analysis (BAI-305)
Semester: III (BCA – AIDA)
Student: Hammad
Unit-I: Getting Started with R and R Workspace
Submitted To: Department of Computer Applications
LNCT University, Bhopal
UNIT-I: Getting Started with R and R Workspace
1. Introduction to R:
R is an open-source programming language designed for statistical computing, data
visualization, and data analysis. It supports data mining, machine learning, and graphical
representation of data.
2. R as a Programming Language:
R supports procedural, object-oriented, and functional programming paradigms. It
provides a wide range of built-in functions and supports user-defined functions for flexibility
in data manipulation.
3. Need of R:
R is essential for analyzing complex datasets and creating detailed reports. It is widely
used in academia, research, and data science because of its accuracy and visualization
tools.
4. Installing R:
- Visit the CRAN website: https://cran.r-project.org/
- Choose your operating system and download the installer.
- Follow on-screen instructions to install R.
5. Installing RStudio:
RStudio is an Integrated Development Environment (IDE) for R. It simplifies programming
by providing an editor, console, environment window, and plotting interface.
Steps:
1. Visit https://posit.co/download/rstudio/
2. Download RStudio Desktop (free version).
3. Install and link it with R.
6. RStudio Interface:
RStudio has four main panels:
• Source Pane – for writing and saving scripts.
• Console Pane – for running R commands.
• Environment/History – displays variables and previous commands.
• Files/Plots/Packages/Help – manages project files and visualizations.
7. R Workspace:
Workspace stores all active variables, functions, and datasets in memory.
Commands:
• ls() – lists all objects.
• rm(x) – removes an object.
• save.image() – saves the workspace.
8. R Project:
R Projects help manage multiple scripts, data files, and results in one place. Use “File →
New Project” in RStudio to create a project folder.
9. Packages in R:
Packages extend R’s functionality. Common ones include:
• ggplot2 – data visualization
• dplyr – data manipulation
• tidyr – data cleaning
Commands:
install.packages("ggplot2")
library(ggplot2)
10. Inspecting Environment:
The str() function shows the internal structure of an object.
Example:
x <- data.frame(a=1:3, b=4:6)
str(x)
11. Modifying Global Options:
You can control global R settings using options().
Example:
options(warn=-1) – disables warnings.
12. Working Directory:
The working directory is where R reads and saves files.
Commands:
getwd() – displays the current directory.
setwd("C:/Users/Hammad") – sets a new directory.
13. Importing and Exporting Data:
R can import and export files in various formats.
Example:
data <- read.csv("input.csv")
write.csv(data, "output.csv")
14. Masking and Conflicts:
When two packages have the same function name, the most recently loaded package
masks the previous one. Use conflicts() to identify conflicts.
Conclusion:
Unit 1 introduces the R environment, setup, RStudio interface, and essential commands
for managing workspace and packages. It forms the foundation for advanced R
programming and data analysis.