Exp-1 page 1-7 (1)
Exp-1 page 1-7 (1)
& Name
EXPERIMENT NO. 01
WHAT IS R?
_____________________
Signature of Faculty
Experiment No. & Name
_____________________
Signature of Faculty
Experiment No. & Name
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 =.
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
we learnt before. The simplest way to build a vector in R, is to use the c command.
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
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.
_____________________
Signature of Faculty
Experiment No. & Name
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
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:
_____________________
Signature of Faculty
Experiment No. & Name
_____________________
Signature of Faculty
Experiment No. & Name
_____________________
Signature of Faculty