Week 1
v1=c(2,5,8)
v2=c(4,9,35)
print(v1+v2)
## [1] 6 14 43
v2=c(4,9,35)
print(sum(v2))
## [1] 48
print(mean(v2))
## [1] 16
print(prod(v2))
## [1] 1260
v2=c(4,9,35)
min(v2)
## [1] 4
max(v2)
## [1] 35
l=list(c(1,4,7,9),matrix(c(1:9),nrow=3),list(c(8:15)))
names(l)=c("one","two","three")
print(l)
## $one
## [1] 1 4 7 9
##
## $two
## [,1] [,2] [,3]
## [1,] 1 4 7
## [2,] 2 5 8
## [3,] 3 6 9
##
## $three
## $three[[1]]
## [1] 8 9 10 11 12 13 14 15
mat1=matrix(c(1:15),nrow=3,ncol=5)
print(mat1)
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 4 7 10 13
## [2,] 2 5 8 11 14
## [3,] 3 6 9 12 15
mat1=matrix(c(1:15),nrow=3,ncol=5)
print(mat1[2,3])
## [1] 8
print(mat1[3,])
## [1] 3 6 9 12 15
print(mat1[,4])
## [1] 10 11 12
df=data.frame(
name=c("ram","shiva"),
age=c(18,19),
marks=c(28,39)
)
print(df)
## name age marks
## 1 ram 18 28
## 2 shiva 19 39
df=cbind(df,gender=c("male","male"))
print(df)
## name age marks gender
## 1 ram 18 28 male
## 2 shiva 19 39 male
df=rbind(df,c("laxmi",19,40,"male"),c("bhanu priya",18,50,"female"))
print(df)
## name age marks gender
## 1 ram 18 28 male
## 2 shiva 19 39 male
## 3 laxmi 19 40 male
## 4 bhanu priya 18 50 female
df[1:3,]
## name age marks gender
## 1 ram 18 28 male
## 2 shiva 19 39 male
## 3 laxmi 19 40 male
df[order(names(df))]
## age gender marks name
## 1 18 male 28 ram
## 2 19 male 39 shiva
## 3 19 male 40 laxmi
## 4 18 female 50 bhanu priya
df1=data.frame(names=c("john","wick"),marks=c(18,19))
df2=data.frame(names=c("bhanu","prasad"),marks=c(15,16))
rbind(df1,df2)
## names marks
## 1 john 18
## 2 wick 19
## 3 bhanu 15
## 4 prasad 16
df[which.max(df$marks),]
## name age marks gender
## 4 bhanu priya 18 50 female
data=read.csv("C:/Users/java/Downloads/ICC Test Batting Figures.csv")
str(data)
## 'data.frame': 3001 obs. of 12 variables:
## $ Player : chr "SR Tendulkar\xa0(INDIA)" "RT Ponting\xa0(AUS)" "JH Kallis\xa0(ICC/SA)" "R Dravid\xa0(ICC/INDIA)" ...
## $ Span : chr "1989-2013" "1995-2012" "1995-2013" "1996-2012" ...
## $ Mat : int 200 168 166 164 161 134 131 164 149 156 ...
## $ Inn : chr "329" "287" "280" "286" ...
## $ NO : chr "33" "29" "40" "32" ...
## $ Runs : chr "15921" "13378" "13289" "13288" ...
## $ HS : chr "248*" "257" "224" "270" ...
## $ Avg : chr "53.78" "51.85" "55.37" "52.31" ...
## $ X100 : chr "51" "41" "45" "36" ...
## $ X50 : chr "68" "62" "58" "63" ...
## $ X0 : chr "14" "17" "16" "8" ...
## $ Player.Profile: chr "http://stats.espncricinfo.com/ci/content/player/35320.html" "http://stats.espncricinfo.com/ci/content/player/7133.html" "http://stats.espncricinfo.com/ci/content/player/45789.html" "http://stats.espncricinfo.com/ci/content/player/28114.html" ...