Home Data Analysis using R

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.

A<-25
B<-29

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 "".

A<-"Arsenal"

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<-is.numeric(B)
> C
[1] TRUE

Finding a data type

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

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

 

 

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
wpDiscuz
0
0
Would love your thoughts, please comment.x
()
x
Exit mobile version