Search This Blog

Tutorial # 1. Data Type & Variable Declaration

 Variable Declaration :

Boolean Type :
a = TRUE
Number Type:
b=5.5
Capital L means this number has to be an Integer
c=6L
String Type Variable
ch =' Hello'
d = charToRaw('Hello World')
# 48 65 6c 6c 6f 20 57 6f 72 6c 64 This is the way how data is stored as row.
 print(d)
Gives the type of a variable 

typeof(a)
typeof(b)
typeof(c)
typeof(ch)
typeof(d)

Gives the data type of a variable
 
class(a)
class(b)
class(ch)
class(d)


In many computer programming languages to assigning a value to a variable 
we generally use "=" 
but in R instead of "=" we can we can also use "<-" but both of them are not same
 
num = 20
num <- 20
Example :
a =1:10
b <- 5:15
print(a)
print(b)
 
mean(x=1:10)
# can't print the value of x as it is a local variable within the mean function  
print(x)

mean(x<-5:15)
# now x is a global variable and can be used anywhere within the program. 
print(x)

You may also interested in:

An Introduction to language R
Tutorial # 1.Data Type & Variable  Declaration
Tutorial # 2.Operators
Tutorial # 3.Vector  & Element Access
Tutorial # 4.Matrix
Tutorial # 5.Data Frame
Tutorial # 6.Arrays
Tutorial # 7.Lists
Tutorial # 8.Factors
Tutorial # 9.Data import
Tutorial # 10.Machine Learning
Tutorial # 11.Visualization


Post a Comment

0 Comments