0% found this document useful (0 votes)
5 views9 pages

Exp-1 page 1-7 (1)

The document provides an introduction to R programming, detailing its history, capabilities, and basic data types. It covers essential concepts such as variables, vectors, matrices, and factors, along with their syntax and usage in R. Additionally, it highlights the importance of R in data analysis and its application in various industries.

Uploaded by

2022bit021
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)
5 views9 pages

Exp-1 page 1-7 (1)

The document provides an introduction to R programming, detailing its history, capabilities, and basic data types. It covers essential concepts such as variables, vectors, matrices, and factors, along with their syntax and usage in R. Additionally, it highlights the importance of R in data analysis and its application in various industries.

Uploaded by

2022bit021
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/ 9

Experiment No.

& Name

Page No: Date:

EXPERIMENT NO. 01

AIM: R PROGRAMMING INTRODUCTION AND BASICS

WHAT IS R?

R is a programming language developed by Ross Ihaka and Robert Gentleman in 1993. R


possesses an extensive catalog of statistical and graphical methods. It includes machine learning
algorithm, linear regression, time series, statistical inference to name a few. Most of the R libraries
are written in R, but for heavy computational task, C, C++ and Fortran codes are preferred. R is
not only entrusted by academic, but many large companies also use R programming language,

_____________________
Signature of Faculty
Experiment No. & Name

Page No: Date:

including Uber, Google, Airbnb, Facebook and so on.

Data analysis with R is done in a series of steps; programming, transforming, discovering,


modeling and communicate the results

Basic data types

_____________________
Signature of Faculty
Experiment No. & Name

Page No: Date:

Data Types R Code Output

# Boolean z< TRUE


class(z)

Variables store values and are an important component in programming, especially for a data
scientist. A variable can store a number, an object, a statistical result, vector, dataset, a model
prediction basically anything R outputs. We can use that variable later simply by calling the name
of the variable. To declare a variable, we need to assign a variable name. The name should not
have space. We can use _ to connect to words. To add a value to the variable, use <- or =.

SYNTAX RCODE OUTPUT


# First way to declare a variable: use the
`< `name_of_variable < value
# Second way to declare a variable: use the
`=`
name_of_variable = value

Vectors

A vector is a one-dimensional array. We can create a vector with all the basic data type

_____________________
Signature of Faculty
Experiment No. & Name

Page No: Date:

we learnt before. The simplest way to build a vector in R, is to use the c command.

Vectors Type Rcode OUTPUT

Operator Description RCode OUTPUT

Arithmetic
+ Addition 3+4 ## [1] 7
- Subtraction ## [1] 2
* Multiplication ## [1] 15
/ Division ## [1] 5
^ or ** Exponentiation ## [1] 32

_____________________
Signature of Faculty
Experiment No. & Name

Page No: Date:

Logical

What is a Matrix?

A matrix is a 2-dimensional array that has m number of rows and n number of columns. In other
words, matrix is a combination of two or more vectors with the same data type. Note: It is
possible to create more than two dimensions arrays with R.

SYNTAX: matrix(data, nrow, ncol, byrow = FALSE) Arguments:

_____________________
Signature of Faculty
Experiment No. & Name

Page No: Date:

We can select elements one or many elements from a matrix by using the square brackets [ ].
This is where slicing comes into the picture.

For example:

_____________________
Signature of Faculty
Experiment No. & Name

Page No: Date:

What is Factor in R?

Factors are variables in R which take on a limited number of different values; such
variables are often referred to as categorical variables. In a dataset, we can distinguish two types
of variables: categorical and continuous. In a categorical variable, the value is limited and usually
based on a particular finite group. For example, a categorical variable can be countries, year,
gender, occupation. A continuous variable, however, can take any values, from integer to decimal.
For example, we can have the revenue, price of a share, etc..

R stores categorical variables into a factor. Let's check the code below to convert a
character variable into a factor variable. Characters are not supported in machine learning
algorithm, and the only way is to convert a string to an integer.

RCODE:

# Create gender vector

gender_vector < c("Male", "Female", "Female", "Male")

_____________________
Signature of Faculty
Experiment No. & Name

Page No: Date:

_____________________
Signature of Faculty
Experiment No. & Name

Page No: Date:


4

_____________________
Signature of Faculty

You might also like