Basic Syntax: Variables in R

As part of series Learn Data analytics using R lets understand basic syntax in this post.

Numeric Data Type

Lets say you want to create two variable A and B. In R program you shall assign a value to the variable using <- . Now, if you want to assign 25 to A and 29 to B. You can use the following code.


You can add both variable by simply using + operator

> A+B
[1] 54

Character Data Type

The above example is for assigning numeric value. If you need to assign a character/word to the variable you can do so by adding a quotations "".


Now, Variable A is assigned with a text value of “Arsenal”. Character and Numeric are data types.

Logical Data Type

R is also capable of storing Logical data type like TRUE/FALSE

> C
[1] TRUE

Finding a data type

You can use class() to find the data type of a variable

[1] "character"
> class(B)
[1] "numeric"
> class(C)
[1] "logical"



Leave a Reply

Your email address will not be published.