0% found this document useful (0 votes)
27 views13 pages

R Programming

R is a powerful and widely used programming language for statistical computing and data analysis. It was developed at the University of Auckland and is now maintained by the R Development Core Team. R uses several programming paradigms including functional programming, vectorized programming, object-oriented programming, and statistical programming. It has a variety of language constructs like variables and data types, operators, control structures, functions, and input/output capabilities. R is commonly used for data analysis, statistics, data visualization, and machine learning.

Uploaded by

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

R Programming

R is a powerful and widely used programming language for statistical computing and data analysis. It was developed at the University of Auckland and is now maintained by the R Development Core Team. R uses several programming paradigms including functional programming, vectorized programming, object-oriented programming, and statistical programming. It has a variety of language constructs like variables and data types, operators, control structures, functions, and input/output capabilities. R is commonly used for data analysis, statistics, data visualization, and machine learning.

Uploaded by

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

R PROGRAMMING

22N203- Aditya D P 22N244 - Sahishnuram S


22N227- Kishor G 22N248 - Santhosh M
22N238 - Prathish RH 22N264 - Vanchit Visanth M S
Intro to R
R is a powerful and widely used programming language and software environment
for statistical computing and data analysis. It was developed by Ross Ihaka and
Robert Gentleman at the University of Auckland, New Zealand, and is now
maintained by the R Development Core Team. R provides a wide variety of
statistical and graphical techniques and is extensible through packages.

KEY FEATURES:

1.Open Source

2.Data visualization

3.Extensive packages
Programming Paradigm
1) Functional Programming:

● First-Class Functions: In R, functions are first-class objects, which means you can pass
them as arguments to other functions, return them as values from other functions, and
assign them to variables.

● Higher-Order Functions: Functions that take other functions as arguments or return


functions are common in R. This allows for concise and expressive code.

2) Vectorized Programming:

● R is designed with vectorization in mind. Operations can be applied to entire vectors or


matrices without the need for explicit looping. This leads to more concise and efficient code.

● Functions like apply(), lapply(), and sapply() are often used for vectorized
operations.
3) Object-Oriented Programming (OOP):

● S3 Classes: Simple and flexible. Objects have a class attribute that defines their type,
and methods are often generic functions that behave differently based on the class of
their arguments.

● S4 Classes: More formal and structured than S3 classes. They allow for stricter
object-oriented design.

4)Statistical Programming:

● R is particularly well-suited for statistical programming and analysis. It provides


a wide range of statistical functions and libraries for various statistical models
and analyses.
Language Constructs??
Language constructs are the fundamental elements or components that make up a
programming language. They are the building blocks used to create programs by
defining and manipulating data, performing operations, controlling the flow of
execution, and organizing code. Language constructs vary among programming
languages, but they generally include the following categories:

● Variables and data types


● Operators
● Control structures
● Functions
● Comments
● Variables and Data types

● Operators
Language ● Control Structures

Constructs ● Functions

● Input and Output


Variables and Data Types
Variables are symbolic names that represent a
value or data. In R, you declare a variable using
the <- (assignment) operator. ‘x <- 10’: Assigns
the value 10 to the variable x.

Here, x is a numeric variable. ‘name <- "John"’:


assigns the string "John" to the variable name.
name is a character variable. ‘is_student <-
TRUE’: Assigns the logical value TRUE to the
variable is_student. ‘is_student’ is a logical
(boolean) variable.R is dynamically typed,
meaning it automatically determines the data type
based on the assigned value.

In this example, x is of type numeric, name is of


type character, and is_student is of type logical.
Operators
result_addition <- x + 5: Adds 5 to the value
stored in the variable x.

If x is 10, then result_addition will be 15.

result_multiplication <- x * 2: Multiplies the


value stored in the variable x by 2.

If x is 10, then result_multiplication will be 20.

is_greater_than <- x > 5: Checks if the value


stored in the variable x is greater than 5.

If x is 10, then is_greater_than will be TRUE


because 10 is greater than 5.
Control Structures
x > 0: This checks if the value stored in the
variable x is greater than 0.

If the condition (x > 0) is TRUE, the code block


inside the first set of curly braces {} is executed:

If the condition is FALSE, the code block inside the


second set of curly braces {} is executed:
Functions
Function definition in R involves specifying the
function name, parameters, and the operation to be
performed.

Function calls involve using the function name with


parentheses and passing any required arguments.

This example calls the square function with the


argument 4 and assigns the result to the variable
result

When the function is called, the argument 4 is


passed to the parameter num in the function.

The function computes num^2 (square of the


argument) and returns the result.
Input and Output
readline() is a function in R used for reading input
from the console.

When this code is executed, the program will pause


and wait for the user to type something in response
to the prompt.The user's input is then stored in the
variable user_input.

cat() is a function used for concatenating and


printing values to the console.

The cat() function concatenates the string "Hello, "


with the user's input (user_input) and the
exclamation mark ("!\n" for a newline character).

The result is then printed to the console.


Applications
Data Analysis and Statistics: R is widely used for statistical analysis, hypothesis
testing, and data exploration. It provides a rich set of functions for descriptive
statistics, inferential statistics, and probability distributions.

Data Visualization: The ggplot2 package in R is renowned for creating


high-quality data visualizations. R offers a variety of plotting options, including
scatter plots, bar charts, histograms, and more, making it a powerful tool for data
visualization.

Machine Learning and Predictive Modeling: R has extensive machine learning


libraries, such as caret and randomForest, allowing data scientists to build and
evaluate predictive models. It supports a range of algorithms for classification,
regression, clustering, and more.
THANK YOU

You might also like