We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 9
. Learn all the basics of R-Programming (Data types & Operators)
# Datatypes — Numeric, Character, Complex, Integer, Logical aud Raw
bI=1.234
print(b1)
typeof{bl)
class(b1)
is. mumerie(b1)
al=as.character(b1)
print(al)
typeoftal)
is.character(al)
cl=as.complex(al)
print(cl)
typeof{el)
is.complex(el)
di-as.integer(bl)
print(é1)
is.integer(d1)
el<(TRUE)
print(el)
typeoffel)
is logical(el)
# specifying and check raw datatype
raw] < charToRaw("Learning R Programming")
cat(rawl)
cat("The data type of raw! is ",class(raw!),"n\n")
charl < rawToChar(raw1)
print(charl)
cat("The data type of cher] is ",class(charl),"\n\n")
# Specifying and checking Arithmetic Operators such as ~, -, *,/, 6%, %/%, ®
a<105
print(a)
b<10
print(b)
add <- print(a+b)
cat("Addition of a & b is: ", add)
sub < print(a-b)cat("Subtraction of a & b is: ", sub)
mul <- print(a*b)
cat("Multiplication ofa & bis: ", nl)
iv <- print(aib)
cat("Division of a & b is: ", div)
Rem < print(a%°%ab)
cat("Modulous of a & bis: " Rem)
Int_Quo < print(a %% b)
cat("Quotiont of a &b is: " Int_ Quo)
Exp <- print(a “b)
cat("Exponentiation of a & b is: " ,EXp)
# Specifying and checking Relational operators
varll =12
varl2 = 56.8
varl3 < 12
print(varl1>varl2)
print(varl1—varl3)
print(var12>varl3)
print(varl 1 !=varl3)
print(varl1<=varl3)
print(var12>=varll)
Write an R program to create, accessing elements vector operations on atomic vector.
# Creating a vector with : (colon) operator
ai)
log_vec
class(log_vee)
# In R, we use the rep() fimction to repeat elements of vectors.
# repeat sequence of vector 2 times
mumbers < rep(e(2,4,6), times = 2)
cat("Using times argument", numbers)
m< rep(‘a’,9)
m
# Accessing elements of vectors using 3 ways. Integer indexing, Character indexing,
Logical indexing3.
# Indexing with integer vector
seq_vee{1]
seq_vec[6]
seq_vec[3:6]
# Indexing with a character vector
char_vee