Assign value
To assign a value we use the ‘<-’ symbol.
Like in usual programming language after assigning the value to test/evaluate, we can use print keyword to print the value. The above example was executed in console window. So it’s much easier to just type the variable to show the values rather than explicitly print. When we are printing R vector we can see [ ] brackets. In our above example its shown in the output indicates that ‘hello’ is a vector and 100 is its first element.
Comments
Unlike other programming language R doesn’t support multiple line comments. Therefore, only single line comment with ‘#’ character work with R language.
Data Types
In any programming language we need various variables to implement our logics. Comparing to other programming language R, variables are not declared as some data type. The mostly used R-objects are,
- Vectors
- Lists
- Matrices
- Arrays
- Factors
- Data Frames
Vectors
The basic type of R object is a vector. A vector can only contain objects of the same class. It can contain the following basic classes of objects:
- Logical
- Numeric
- Integer
- Complex
- Character
If you want to assign more than one element in a vector, we should use ‘c()’ function.
List
A list represents has vector but can contain different objects of classes.
Matrices
It’s like vectors but with ‘dimension’ attributes (two-dimensional data set). It contains row and column size.
Arrays
Unlike matrices array can be created with any number of dimensions.
Factors
It’s used to store categorical data. Factors are important in statistical modeling and this feature will be very handy to use. Basically its like keeping label in a vector.
Data Frame
It’s something similar to matrices but with different data objects in columns. Therefore, it helps to store tabular data in R Language.