You are on page 1of 5

Experiment 1

Name – Afsar Ansari


Class – SEDA – B
PRN No – 12020154
Roll No – 23
Batch-B1

Q1- Internal Dataset:

R has internal data sets which can be used for study purpose.
>data() ## It gives the list of internal datasets available.
e.g “women” : Average height and weight of American women.
“ Titanic” : Survival of passengers on Titanic.
“mtcars” :Motor trend car road tests.
>help(data set name) ## It gives the details about the dataset

INPUT CODE
a=10
b<-15
c<-"Hello"
objects()#to see the list of objects created in the
mode(a)
mode(c)
length (c)
e<-c(a,b)
d<-c(e,c)
#creating data frames
data<-data.frame (x=1:3,y=4:6,z=c("One","two","three"))
data
str(data)
name<-c("Tendulkar","Pointing","Kallis")
Matches<-c(200,156,178)
cricket<-data.frame(name,Matches)
View(cricket)
innings<-c(298,234,233)
cricket<-cbind(cricket,innings)
View(cricket)
V<-data.frame(name="Dravid",Matches=178,innings=201)
cricket<-rbind(cricket,V)
str(cricket)
#access the element of the data frame
#accessing by index
cricket[2,2]
cricket[2,3]#access the 2nd row 3rd colmn elememt
cricket[2,]#access the 2nd row elememt
cricket[,3]#access the 3rd colmn elememt
cricket[,c(1,3)]
#Accessing by column name
cricket$name
#Accessing by condition
cricket[cricket$name=="Tendulkar",]#access the row corresponding to
playerTendulkar
cricket[cricket$name=="Tendulakar",4]# to find highestscore of Tendulkar
which(cricket$highestscore>=270,)# Find the row number of thedata for which
the highestscore is equal or greater than 270
cricket[which(cricket$highestscore==max(cricket$highestscore)),c(1,5)]
cricket[cricket$name=="Tendulakar",2]<-201# Modify Tendulkar's number of
matches as 201.

You might also like