0% found this document useful (0 votes)
9 views2 pages

20222MBA0121 - Isha Sahu

Uploaded by

Gowtham Dinesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

20222MBA0121 - Isha Sahu

Uploaded by

Gowtham Dinesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#variable are nothing but reserved memory locations to store values this means that

when you create a variable you reserve some space in memory

name<- "isha" #leftward variable assign


"neha"-> nick #rightward variable asssign
print(name)
print(nick)
age<- 23
print(age)

#vector is a sequence of data elements of the same basic type


#logical
vctr1<- c(TRUE,FALSE)
class(vctr1)
print(vctr1)

#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)

numb<- list(1:5) #creats a list from 1 to 5


print(numb)

#matrix are the R objects in which the elements are arranged in A 2Dimensional
layouts (rowXcol)

mymatrix <- matrix(c(1,2,3,4,5,6), nrow = 3, ncol = 2) #creates matrix with 3 rows


and 2 columns
print(mymatrix) #print the whole matrix
print(mymatrix[1,2]) #print the element at 1st row 2nd column
print(mymatrix[1,]) #prints the whole row-1
print(mymatrix[,2]) #print the whole column-2

#Data Frames are data displayed in a format as a table.


Data_Frame <- data.frame (
Training = c("Strength", "Stamina", "Other"),
Pulse = c(100, 150, 120),
Duration = c(60, 30, 45)
)
print(Data_Frame)
print(Data_Frame[2]) #prints the 2nd row
print(Data_Frame[["Training"]]) #one way to print the values of "Training" row
print(Data_Frame$Training) #other way to print the values of "Training" row

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

# create a class "Student_Database" with three member variables


setClass("Student_Database", slots=list(name="character", age="numeric",
total="numeric"))

#creating an object of the above defined class


student1<- new("Student_Database", name="Isha", age = 22, total=8.7)

print(student1)

You might also like