20222MBA0121 - Isha Sahu
20222MBA0121 - Isha Sahu
#numeric
vctr2<- c(3.6,7.9,2.89)
class(vctr2)
print(vctr2)
#integer
vctr3<- c(3L,8L,2L)
class(vctr3)
print(vctr3)
#characters
vctr4<- c("isha","kriti","shraddha")
class(vctr4)
print(vctr4)
#list are the R objects which conatins elements of different types like
numbers,strings,vectors and another list inside it
cartoon<- list("tom","jerry","hattori","doremon")
length(cartoon) #prints the length of the list
print(cartoon) #prints the whole list
print(cartoon[1]) #print the element with 1st index i.e. the 2nd element (as list
are 0 based)
cartoon[2]<- "pokemon" #updates the list, element at index 2 is replaced with
"pokemon"
print(cartoon)
#matrix are the R objects in which the elements are arranged in A 2Dimensional
layouts (rowXcol)
#functions
#pre-defined functions
print(max(18:14)) #find the maximum
print(min(18:14)) #find the minimum
#user-defined functions
checkEvenOdd = function(x){
if(x %% 2 == 0)
return("even")
else
return("odd")
}
print(checkEvenOdd(7))
print(checkEvenOdd(18))
#object are the Instance of the class Also, everything in R is an object and to
know more look at Data types in R. They also can have their attributes like class,
attributes,dimnnames, names, etc.
print(student1)