0% found this document useful (0 votes)
19 views

R Lanaguage

Uploaded by

aryan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

R Lanaguage

Uploaded by

aryan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

INTRODUCTION ON “R” LANGUAGE

is a programming language and environment primarily used for statistical computing,

data analysis, and graphical representation. It was developed by statisticians Ross Ihaka and

Robert Gentleman in the mid-1990s and is open-source, which means it is freely available to

anyone. R is widely used by statisticians, data scientists, and researchers for tasks such as:

 Statistical analysis: R provides a wide array of statistical techniques, including linear and

nonlinear modeling, classical statistical tests, time-series analysis, and clustering.

 Data visualization: R has strong capabilities for producing high-quality plots and charts.

Libraries like ggplot2 allow users to create detailed and customizable visualizations.

 Data manipulation: Packages like dplyr and tidyr make it easy to clean, filter, and

manipulate large datasets.

 Machine learning: R is also used for machine learning tasks, offering tools for building

predictive models and performing analysis on large datasets.

R's extensibility comes from its active user community, which has contributed thousands of

packages available through the Comprehensive R Archive Network (CRAN).


INSTALLATION OF R SOFTWARE ON WINDOW

Step-1-Go to the CRAN website

Step-2- Click on “Download R for Window”.


Step-3-Click on "install R for the first time" link to download the R executable
(.exe) file.

Step-4-Click on "Finish" to exit the installation setup.


R has now been successfully installed on your Windows OS.
Open the R GUI to start writing R codes.
INTRODUCTION OF R STUDIO

is an integrated development environment (IDE) designed specifically for working


with the R programming language. It provides a user-friendly interface for writing R code,
executing it, and managing projects, making it easier to perform statistical analysis, data
visualization, and data manipulation.

Key Features:

 Code Editor: A text editor with syntax highlighting, auto-completion, and debugging
tools to write and run R code efficiently.

 Console: A space to run R commands interactively, allowing users to test code snippets or
run scripts directly.

 Environment/History Pane: Displays variables, data frames, and functions loaded into
the R environment, along with a record of previously executed commands.

 Plots and Viewer Pane: Allows users to view plots, graphs, and visualizations directly
within RStudio, as well as browse files and manage packages.

 Package Management: Easily install, update, and load R packages from CRAN or other
sources.

 Projects: Organize scripts, data, and files related to specific projects.

RStudio makes the R language more accessible, especially for beginners, by integrating various
tools into one environment. It’s widely used in data science, academic research, and statistical
analysis.
INSTALLATION OF R STUDIO SOFTWARE ON WINDOW

Step-1-First, you need to set up an R environment in your local machine. You can
download the same from “r-project.org” and click Install Rstudio.

Step-2- click “NEXT”


Step-3- click “Finish”

User Interface of Rstudio:-


PROGRAM DESCRIPTION

1-Data Types:-
 Numeric:- Numeric data type stores numbers, which can be integers or real (floating-
point) numbers.

X = 3.14
Y=5

Output:

 Logical(Boolean):- Logical data type stores TRUE or FALSE values, often used for
condition checking.
> X=TRUE
> Y=FALSE

Output:

 Integer:- Integer stores whole numbers (without a fractional part).

> x<-as.integer(42)
>x

Output:
2- variables:- variables are used to store data that can be referenced and manipulated
throughout the code. You assign values to variables and use them to store various data types like
numbers, strings, vectors, or data frames.

 Numeric Varibales:-
> num_var<-10.5
> print(num_var)

Output:
 Logical (Boolean) Variable:-

> bool_var <- TRUE


> print(bool_var)
Output:
 Integer Variable:-

> int_var <- as.integer(42)


> print(int_var)
Output:
3- R objects : -
 Vectors:- Vectors are the simplest R objects and contain elements of the same data type
(either numeric, character, or logical).
> num_vec<-c(1,2,3,4,5)
> char_vec<-c("apple","banana","cherry")
> log_vec<-c(TRUE,FALSE,TRUE)

Output:

 Lists:- Lists can hold elements of different types (numbers, strings,


vectors, or even other lists).

>my_list<-list(name = "alice",age=25,scores
=c(85,90,88),is_student=TRUE)

> print(my_list)

Output:
 Matrices:- A matrix is a two-dimensional array where all elements are
of the same type (numeric, character, or logical).

> mat<-matrix(1:9,nrow=3,ncol=3)

> print(mat)

Output:-
 Arrays:- Arrays are similar to matrices but can have more than two
dimensions. They can hold data in multiple dimensions, all of the same
type.

> arr<-array(1:18, dim=c(3,3,2))

> print(arr)

Output:-
 Factors:- Factors are used to represent categorical data and store both
the values and the corresponding category levels.

> gender<-factor(c("male","female","female","male"))

> print(gender)

Output:
 Data Frames:- Data frames are tables or 2D arrays in which each
column can contain different types of data (numeric, character, etc.).
They are used to store datasets.

> df <- data.frame(

+ Name = c("john","Alice", "Bob"),


+ Age = c(30,25,35),

+ score = c(90,85,88)

+)

Output:
4- R operators :-
 Arthematic operators:- Arithmetic operators are used for mathematical calculations.
> a<-10
> b<-3
> sum_resukt<-a+b
> div_result<-a/b
> mod_result<-a%%b
> exp_resukt<-a^b
Output:

 Relational operators:- Relational operators are used to compare two values or variables.
> x<-15
> y<-10
Output:

 Logical operators:- Logical operators are used to combine or modify logical statements.
> x=10
> y=20
> z=5
> sum_result=x+y
> product_result=x*y
Output:
PROGRAM DISCRIPTION

The basic functions in r and implement with examples:

A function is a set of statements organized together to perform a specific task. R has a large
number of in-built functions and the user can create their own functions.
In R, a function is an object so the R interpreter is able to pass control to the function, along with
arguments that may be necessary for the function to accomplish the actions.
The function in turn performs its task and returns control to the interpreter as well as any result
which may be stored in other objects.
Benefits of Using Functions:
Code Reusability: Once written, functions can be reused in different parts of a program without
rewriting code.
Modularity: Functions break down large problems into smaller, manageable blocks.
Maintenance: Easier to maintain and update code as modifications in one function do
not affect others.

Built-in Functions in R
R provides a variety of built-in functions that are ready to use for performing different operations,
from mathematical calculations to data manipulation. Some common categories of built-in
functions include:

 Mathematical Functions:

1- sum(): Returns the sum of all elements in a vector.

2- mean(): Computes the arithmetic mean.


3- sqrt(): Returns the square root of a number.

4- log(): Computes the natural logarithm.

5- abs(): Returns the absolute value of a number

6- prod(): Returns the product of all elements in a vector.

7- min(): Finds the minimum value in a vector.

8- max(): Finds the maximum value in a vector.


9- round(): Rounds a number to the specified number of decimal places.

10- factorial(): Computes the factorial of a number.

11- choose(n, k): Computes the binomial coefficient (n choose k).

 Statistical Functions:-

1- mean(x): Calculates the arithmetic mean.

You might also like