LEARNING R ON YOUTUBE

How to Assign Values to Object using “=” or “<-”

x = 11
print(x)
## [1] 11
x
## [1] 11
y <- 7
y
## [1] 7
y <- 9
y
## [1] 9

How to use ls() to see the data stored in R

ls()
## [1] "x" "y"

How to use rm() to remove object in R

rm(y)
y <- 9
y
## [1] 9

Naming Object

x.1<- 14
x.1
## [1] 14

Defining Characters

xx <- "Abdullateef"
xx
## [1] "Abdullateef"
yy <- "1"

Performing Arithmetic Operation in R

11 + 14
## [1] 25
7 * 9
## [1] 63
x +y
## [1] 20
z <- x+y
z
## [1] 20
x-y
## [1] 2
x*y
## [1] 99
x/y
## [1] 1.222222
y^2
## [1] 81
x^2 + y^2
## [1] 202

Using the Sqrt(), Log(), Exp() and #abs()

sqrt(y)
## [1] 3
y^(1/2)
## [1] 3
log(y)
## [1] 2.197225
exp(y)
## [1] 8103.084
log2(y)
## [1] 3.169925
abs(-14)
## [1] 14
sqrt(y)
## [1] 3

Vector

 x1 <- c(1,3,5,7,9)
x1 
## [1] 1 3 5 7 9
gender <- c("male","female")
gender
## [1] "male"   "female"

Using “:” and seq() to create sequence of numbers

2:7
## [1] 2 3 4 5 6 7
seq(from=1,to=7,by=1)
## [1] 1 2 3 4 5 6 7
seq(from=1,to=7, by=1/3)
##  [1] 1.000000 1.333333 1.666667 2.000000 2.333333 2.666667 3.000000 3.333333
##  [9] 3.666667 4.000000 4.333333 4.666667 5.000000 5.333333 5.666667 6.000000
## [17] 6.333333 6.666667 7.000000
seq(from=1,to=7,by=0.25)
##  [1] 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 3.25 3.50 3.75 4.00 4.25 4.50
## [16] 4.75 5.00 5.25 5.50 5.75 6.00 6.25 6.50 6.75 7.00

Using rep() to create a vector of repeated numbers or character

rep(1, times=10)
##  [1] 1 1 1 1 1 1 1 1 1 1
rep("marin", times=5)
## [1] "marin" "marin" "marin" "marin" "marin"
rep(1:3,times=5)
##  [1] 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3
rep(seq(from=2,to=5,by=0.25),times=5)
##  [1] 2.00 2.25 2.50 2.75 3.00 3.25 3.50 3.75 4.00 4.25 4.50 4.75 5.00 2.00 2.25
## [16] 2.50 2.75 3.00 3.25 3.50 3.75 4.00 4.25 4.50 4.75 5.00 2.00 2.25 2.50 2.75
## [31] 3.00 3.25 3.50 3.75 4.00 4.25 4.50 4.75 5.00 2.00 2.25 2.50 2.75 3.00 3.25
## [46] 3.50 3.75 4.00 4.25 4.50 4.75 5.00 2.00 2.25 2.50 2.75 3.00 3.25 3.50 3.75
## [61] 4.00 4.25 4.50 4.75 5.00
rep(c("m","f"), times=5)
##  [1] "m" "f" "m" "f" "m" "f" "m" "f" "m" "f"

How to perform basic arithmetic functions on elements of a vector

x <- 1:5
x
## [1] 1 2 3 4 5
y<-c(1,3,5,7,9)
x+10
## [1] 11 12 13 14 15

How to perform basic arithmetic functions on elements of a vector

x-10
## [1] -9 -8 -7 -6 -5
x*10
## [1] 10 20 30 40 50
x/2
## [1] 0.5 1.0 1.5 2.0 2.5

How to perform basic arithmetic functions on the corresponding elements of two vectors

x+y
## [1]  2  5  8 11 14
x-y
## [1]  0 -1 -2 -3 -4
x*y
## [1]  1  6 15 28 45
x/y
## [1] 1.0000000 0.6666667 0.6000000 0.5714286 0.5555556

How to extract elements of a vector using square brackets[]

x[2]
## [1] 2
y[3]
## [1] 5
y[-3]
## [1] 1 3 7 9
y[1:3]
## [1] 1 3 5
y[c(1,5)]
## [1] 1 9
y[-c(1,5)]
## [1] 3 5 7
y[y<6]
## [1] 1 3 5

How to create a matrix using “matrix”,“nrow” and “byrow” functions

matrix(c(1,2,3,4,5,6,7,8,9), nrow=3, ncol=3,byrow=F)
##      [,1] [,2] [,3]
## [1,]    1    4    7
## [2,]    2    5    8
## [3,]    3    6    9
matrix(c(1,2,3,4,5,6,7,8,9), nrow=3, ncol=3,byrow=T)
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    4    5    6
## [3,]    7    8    9
mat <- matrix(c(1,2,3,4,5,6,7,8,9), nrow=3, ncol=3,byrow=T)
mat
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    4    5    6
## [3,]    7    8    9

How to extract certain elements from a matrix using the square brackets

mat[1,2]
## [1] 2
mat[c(1,3),2]
## [1] 2 8
mat[2,]
## [1] 4 5 6
mat[,1]
## [1] 1 4 7

How to perform element-wise arithmetic functions in a matrix in R?

mat*10
##      [,1] [,2] [,3]
## [1,]   10   20   30
## [2,]   40   50   60
## [3,]   70   80   90

How to import CSV file into R using read.csv function

data1 <- read.csv("C:/Users/user/Desktop/mbb.csv", 
                    na = "***", header = T)
head(data1)
##     Month Mozart Beethoven Bach
## 1 2004-01     12         8   15
## 2 2004-02     12         9   15
## 3 2004-03     12         9   14
## 4 2004-04     12         8   14
## 5 2004-05     11         9   13
## 6 2004-06      9         7   12

How to import CSV file into R? using read.table function

data2a <- read.table("C:/Users/user/Desktop/mbb.csv", 
                   na = "***", header=T)
head(data2a)
##   Month.Mozart.Beethoven.Bach
## 1             2004-01,12,8,15
## 2             2004-02,12,9,15
## 3             2004-03,12,9,14
## 4             2004-04,12,8,14
## 5             2004-05,11,9,13
## 6              2004-06,9,7,12

How to specify how variables/columns are separated when importing data into R

data2b <- read.table("C:/Users/user/Desktop/mbb.csv", header=T, sep=",")
head(data2b)
##     Month Mozart Beethoven Bach
## 1 2004-01     12         8   15
## 2 2004-02     12         9   15
## 3 2004-03     12         9   14
## 4 2004-04     12         8   14
## 5 2004-05     11         9   13
## 6 2004-06      9         7   12

How to import tab-delimited (.TXT) data file into R? using read.delim function

data3 <- read.delim("C:/Users/user/Desktop/mbb.txt", header=T)
head(data3)
##     Month Mozart Beethoven Bach
## 1 2004-01     12         8   15
## 2 2004-02     12         9   15
## 3 2004-03     12         9   14
## 4 2004-04     12         8   14
## 5 2004-05     11         9   13
## 6 2004-06      9         7   12

How to import tab-delimited (.TXT) data file into R? using read.table function

data4 <- read.table ("C:/Users/user/Desktop/mbb.txt", header=T, sep="\t")
head(data4)
##     Month Mozart Beethoven Bach
## 1 2004-01     12         8   15
## 2 2004-02     12         9   15
## 3 2004-03     12         9   14
## 4 2004-04     12         8   14
## 5 2004-05     11         9   13
## 6 2004-06      9         7   12

How to import Excel Files (.XLSX) data file into R? using readxl function

library(readxl)
data5 <- read_excel("C:/Users/user/Desktop/mbb.xlsx", 
                  na = "***")
head(data5)
## # A tibble: 6 × 4
##   Month   Mozart Beethoven  Bach
##   <chr>    <dbl>     <dbl> <dbl>
## 1 2004-01     12         8    15
## 2 2004-02     12         9    15
## 3 2004-03     12         9    14
## 4 2004-04     12         8    14
## 5 2004-05     11         9    13
## 6 2004-06      9         7    12

How to use the write. table command for exporting data out of R.

write.table(data1, file="mbbdata1.csv", sep=",")

How to get the Working Directory

getwd()
## [1] "C:/Users/user/Documents/ICAMMDA"

How to set the working directory

setwd("C:/Users/user/Documents/ICAMMDA")

How to include or exclude the row names while exporting data out of R using ‘row.names’ argument

write.table(data1, file="mbbdata2.csv", row.names=F, sep=",")

How to save file exported from R to a folder other than the current working directory:

write.table(data1, file="C:/Users/user/Documents/mbbdata2.csv", row.names=F, sep=",")

How to use write.command in for saving in other file formats for example a tab delimited text file

write.table(data1, file="mbbdata2.txt", row.names=F, sep="\t")

How to use the “write.csv” command to export data from R

write.csv(data1, file="mbbdata3.csv", row.names=F)

How to read a dataset into R? we will use read.table function to read a dataset into R and save it as an object

mydata <- read.table(file="C:/Users/user/Documents/ICAMMDA/mbbdata2.csv", header=T,sep=",")

How to know the dimensions (the number of rows and columns) of the data in R using the dim function

dim(mydata)
## [1] 152   4

How to see the first several rows of the data using the head()

head(mydata)
##     Month Mozart Beethoven Bach
## 1 2004-01     12         8   15
## 2 2004-02     12         9   15
## 3 2004-03     12         9   14
## 4 2004-04     12         8   14
## 5 2004-05     11         9   13
## 6 2004-06      9         7   12

How to see the last several rows of the data using the tail()

tail(mydata)
##       Month Mozart Beethoven Bach
## 147 2016-03      6         4   10
## 148 2016-04      5         4   10
## 149 2016-05      5         4    9
## 150 2016-06      5         3    8
## 151 2016-07      4         3    9
## 152              4         3    9

How to check the variable names in R using name()

names(mydata)
## [1] "Month"     "Mozart"    "Beethoven" "Bach"

How to use the dollar sign “$” to extract the variable within a dataset in R

Mozart <- mydata$Mozart
mean(Mozart)
## [1] 8.190789

How to make objects/variables within a data frame accessible in R using the “attach” function

attach(mydata)
## The following object is masked _by_ .GlobalEnv:
## 
##     Mozart
mean(Bach)
## [1] 10.71053

How to un-attach the data in R? working with the “detach” function

detach(mydata)
Mozart
##   [1]  12  12  12  12  11   9   7   7   9  11  11  10  11  11  10  11  11   9
##  [19]   7   7   9  10  11  11 100  25  19  14  15  11   8   8  10  11  11  12
##  [37]  10   9   9   8   8   7   6   6   7   8   8   7   7   7   7   7   7   6
##  [55]   5   5   6   7   7   7   8   8   8   8   8   7   6   7   7   8   8   8
##  [73]   8   8   7   7   7   6   5   5   6   8   9   8   9   8   8   8   8   7
##  [91]   6   6   7   7   8   8   8   7   7   7   7   6   5   5   6   6   6   6
## [109]   7   6   6   6   6   5   5   5   6   6   6   6   6   6   6   6   6   5
## [127]   5   5   5   6   6   6   7   6   6   6   6   5   4   5   5   5   5   6
## [145]   9   6   6   5   5   5   4   4

How to check the type or class of a variable in R using the “class” function in R

attach(mydata)
## The following object is masked _by_ .GlobalEnv:
## 
##     Mozart
class(Mozart)
## [1] "integer"
class(Month)
## [1] "character"
class(Beethoven)
## [1] "integer"
class(Bach)
## [1] "integer"

How to produce summaries for data in R? learn to use the “summary” function in R

summary(mydata)
##     Month               Mozart          Beethoven           Bach      
##  Length:152         Min.   :  4.000   Min.   : 3.000   Min.   : 8.00  
##  Class :character   1st Qu.:  6.000   1st Qu.: 4.000   1st Qu.:10.00  
##  Mode  :character   Median :  7.000   Median : 5.000   Median :10.00  
##                     Mean   :  8.191   Mean   : 5.197   Mean   :10.71  
##                     3rd Qu.:  8.000   3rd Qu.: 6.000   3rd Qu.:11.00  
##                     Max.   :100.000   Max.   :10.000   Max.   :22.00

How to convert a numeric variable to categorical/factor variable in R using “as.factor” function

x <- c(0,1,1,1,0,0,0,0,0,0)
class(x)
## [1] "numeric"
summary(x)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    0.00    0.00    0.00    0.30    0.75    1.00
x <- as.factor(x)
class(x)
## [1] "factor"
summary(x)
## 0 1 
## 7 3

How to use Apply() in R

Stockdata <- read.table(file="~/ICAMMDA/Stockdata.csv", sep = ",",header=T,row.names=1)
Stockdata
##       Stock1 Stock2 Stock3 Stock4
## Day1  185.74   1.47   1605  95.05
## Day2  184.26   1.56   1580  97.49
## Day3  162.21   1.39   1490  88.57
## Day4  159.04   1.43   1520  85.55
## Day5  164.87   1.42   1550  92.04
## Day6  162.72   1.36   1525  91.70
## Day7  157.89     NA   1495  89.88
## Day8  159.49   1.43   1485  93.17
## Day9  150.22   1.57   1470  90.12
## Day10 151.02   1.54   1510  92.14
apply(X=Stockdata,MARGIN=2,FUN=mean )
##   Stock1   Stock2   Stock3   Stock4 
##  163.746       NA 1523.000   91.571
AVG <- apply(X=Stockdata,MARGIN=2,FUN=mean,na.rm=T )
AVG 
##      Stock1      Stock2      Stock3      Stock4 
##  163.746000    1.463333 1523.000000   91.571000
apply(Stockdata,2, mean, na.rm=T)
##      Stock1      Stock2      Stock3      Stock4 
##  163.746000    1.463333 1523.000000   91.571000
colMeans(Stockdata,na.rm=T)
##      Stock1      Stock2      Stock3      Stock4 
##  163.746000    1.463333 1523.000000   91.571000
apply(Stockdata,2,max,na.rm=T)
##  Stock1  Stock2  Stock3  Stock4 
##  185.74    1.57 1605.00   97.49
apply(Stockdata, 2, quantile,probs=c(0.2,0.80),na.rm=T)
##      Stock1 Stock2 Stock3 Stock4
## 20% 156.516  1.408   1489 89.618
## 80% 168.748  1.548   1556 93.546
apply(Stockdata,2,plot,type="l")

## NULL
apply(Stockdata,2,plot,type="l", main="stock", ylab="Price", xlab="Day")

## NULL
apply(Stockdata,1,sum,na.rm=T)
##    Day1    Day2    Day3    Day4    Day5    Day6    Day7    Day8    Day9   Day10 
## 1887.26 1863.31 1742.17 1766.02 1808.33 1780.78 1742.77 1739.09 1711.91 1754.70
rowSums(Stockdata, na.rm=T)
##    Day1    Day2    Day3    Day4    Day5    Day6    Day7    Day8    Day9   Day10 
## 1887.26 1863.31 1742.17 1766.02 1808.33 1780.78 1742.77 1739.09 1711.91 1754.70
plot(apply(Stockdata,1,sum, na.rm=T),type="l",ylab="Total Market Value", xlab = "Day", main="Market Trend")
points(apply(Stockdata,1,sum, na.rm=T),pch=16, col="blue")

Installing Packages

install.packages("GLMsData",repos = "https://cloud.r-project.org")
## Installing package into 'C:/Users/user/AppData/Local/R/win-library/4.4'
## (as 'lib' is unspecified)
## package 'GLMsData' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\user\AppData\Local\Temp\RtmpeyW1kf\downloaded_packages
library(GLMsData)
data(lungcap)
head(lungcap)
##   Age   FEV Ht Gender Smoke
## 1   3 1.072 46      F     0
## 2   4 0.839 48      F     0
## 3   4 1.102 48      F     0
## 4   4 1.389 48      F     0
## 5   4 1.577 49      F     0
## 6   4 1.418 49      F     0
summary(lungcap)
##       Age              FEV              Ht        Gender      Smoke        
##  Min.   : 3.000   Min.   :0.791   Min.   :46.00   F:318   Min.   :0.00000  
##  1st Qu.: 8.000   1st Qu.:1.981   1st Qu.:57.00   M:336   1st Qu.:0.00000  
##  Median :10.000   Median :2.547   Median :61.50           Median :0.00000  
##  Mean   : 9.931   Mean   :2.637   Mean   :61.14           Mean   :0.09939  
##  3rd Qu.:12.000   3rd Qu.:3.119   3rd Qu.:65.50           3rd Qu.:0.00000  
##  Max.   :19.000   Max.   :5.793   Max.   :74.00           Max.   :1.00000
attach(lungcap)

How to Use the “tapply()” Function in R, to Apply a Function to subsets of a Variable or Vector in R

tapply(Age,Smoke,mean,na.rm=T)
##         0         1 
##  9.534805 13.523077
m <- tapply(Age,Smoke,mean)
m
##         0         1 
##  9.534805 13.523077
tapply(Age,Smoke,mean, simplify=F)
## $`0`
## [1] 9.534805
## 
## $`1`
## [1] 13.52308
mean(Age[Smoke==0])
## [1] 9.534805
mean(Age[Smoke==1])
## [1] 13.52308
tapply(Age,Smoke,summary)
## $`0`
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   3.000   8.000   9.000   9.535  11.000  19.000 
## 
## $`1`
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    9.00   12.00   13.00   13.52   15.00   19.00
tapply(Age,Smoke,quantile,probs=c(0.2,0.8))
## $`0`
## 20% 80% 
##   7  12 
## 
## $`1`
##  20%  80% 
## 11.0 15.2
tapply(X=Age, INDEX=list(Smoke,Gender),FUN=mean, na.rm=T)
##           F         M
## 0  9.365591  9.687097
## 1 13.256410 13.923077
mean(Age[Smoke==0 & Gender=="F"])
## [1] 9.365591
mean(Age[Smoke==0 & Gender=="M"])
## [1] 9.687097
mean(Age[Smoke==1 & Gender=="F"])
## [1] 13.25641
mean(Age[Smoke==1 & Gender=="M"])
## [1] 13.92308
head(lungcap)
##   Age   FEV Ht Gender Smoke
## 1   3 1.072 46      F     0
## 2   4 0.839 48      F     0
## 3   4 1.102 48      F     0
## 4   4 1.389 48      F     0
## 5   4 1.577 49      F     0
## 6   4 1.418 49      F     0
by(Age,list(Smoke,Gender), mean, na.rm=T)
## : 0
## : F
## [1] 9.365591
## ------------------------------------------------------------ 
## : 1
## : F
## [1] 13.25641
## ------------------------------------------------------------ 
## : 0
## : M
## [1] 9.687097
## ------------------------------------------------------------ 
## : 1
## : M
## [1] 13.92308
temp <- by(Age,list(Smoke,Gender), mean, na.rm=T)
temp
## : 0
## : F
## [1] 9.365591
## ------------------------------------------------------------ 
## : 1
## : F
## [1] 13.25641
## ------------------------------------------------------------ 
## : 0
## : M
## [1] 9.687097
## ------------------------------------------------------------ 
## : 1
## : M
## [1] 13.92308
temp[4]
## [1] 13.92308

Bar Chart

dim(lungcap)
## [1] 654   5
names(lungcap)
## [1] "Age"    "FEV"    "Ht"     "Gender" "Smoke"
class(names(lungcap))
## [1] "character"
class(Gender)
## [1] "factor"
#Frequeny Table
count <- table(Gender)
count
## Gender
##   F   M 
## 318 336
# Relative Frequency
percent <- table(Gender)/654
percent
## Gender
##         F         M 
## 0.4862385 0.5137615
barplot(count)

barplot(percent, main="TITLE",xlab="Gender",ylab="%")

barplot(percent, main="TITLE",xlab="Gender",ylab="%", las=1)

barplot(percent, main="TITLE",xlab="Gender",ylab="%", las=1, names.arg=c("Female","Male"), horiz=T)

PIECHART

names(count) <- c("Female","Male")
pie(count, main="TTILE HERE")
names(count) <- c("Female","Male")
box()

Boxplot

boxplot(FEV)

quantile(FEV, probs=c(0,0.25,0.5,0.75,1))
##     0%    25%    50%    75%   100% 
## 0.7910 1.9810 2.5475 3.1185 5.7930
boxplot(FEV, main="Boxplot", ylab="Lung Capacity", ylim=c(0,7), las=1)

boxplot(FEV~Gender)

boxplot(FEV~Gender,main="Boxplot by Gender")

boxplot(FEV[Gender=="F"],FEV[Gender=="M"])

Stratified Box Plot

names(lungcap)
## [1] "Age"    "FEV"    "Ht"     "Gender" "Smoke"
AgeGroups <- cut(Age,breaks=c(0,7,9,11,13,15,19), labels=c("<7",'8/9',"10/11","12/13","14/15","16+"))
Age[1:5]
## [1] 3 4 4 4 4
AgeGroups[1:5]
## [1] <7 <7 <7 <7 <7
## Levels: <7 8/9 10/11 12/13 14/15 16+
boxplot(FEV, ylab="Lung Capacity", main="Boxplot of Lung Capacity", las=1)

boxplot(FEV~Smoke, ylab="Lung Capacity", main="Lung Capcity vs Smoke", las=1)

boxplot(FEV[Age>=15]~Smoke[Age>=15], ylab="Lung Capacity", main="Lung Capcity vs Smoke, for 15+", las=1)

Age[1:5]
## [1] 3 4 4 4 4
AgeGroups[1:5]
## [1] <7 <7 <7 <7 <7
## Levels: <7 8/9 10/11 12/13 14/15 16+
levels(AgeGroups)
## [1] "<7"    "8/9"   "10/11" "12/13" "14/15" "16+"
boxplot(FEV~Smoke*AgeGroups, ylab="Lung Capacity", main="Lung Capcity vs Smoke by Age Groups", las=1)

boxplot(FEV~Smoke*AgeGroups, ylab="Lung Capacity", main="Lung Capcity vs Smoke by Age Groups", las=2, col=c(4,2))
box()

boxplot(FEV~Smoke*AgeGroups, ylab="Lung Capacity", main="Lung Capcity vs Smoke, stratified by Age", las=2, col=c("blue", "red"), axes=F, xlab="Age Strata")
box()
axis(2,at=seq(0,10,1), seq(0,10,1), las=1)
axis(1,at=c(1.5,3.5,5.5,7.5,9.5,11.5), labels=c("<7",'8-9',"10-11","12-13","14-15","16+"))
legend(x=10, y=1.5, legend=c("Non-smoke", "Smoke"), col=c(4,2), pch=15,cex=0.8)

Histogram

names(lungcap)
## [1] "Age"    "FEV"    "Ht"     "Gender" "Smoke"
hist(FEV)

hist(FEV, freq=F)

hist(FEV, prob=T, ylim=c(0,0.6))

hist(FEV, prob=T, ylim=c(0,0.6),breaks=20)

hist(FEV, prob=T, ylim=c(0,0.6),breaks=seq(0,16,2))

hist(FEV, prob=T, ylim=c(0,0.6),breaks=seq(0,6,0.25), main="Boxplot of Lung Capacity", xlab="Lung Capacity", las=1)
box()
lines(density(FEV), col=4,lwd=1)

Stem and Leaf PLots

lungcap
##     Age   FEV   Ht Gender Smoke
## 1     3 1.072 46.0      F     0
## 2     4 0.839 48.0      F     0
## 3     4 1.102 48.0      F     0
## 4     4 1.389 48.0      F     0
## 5     4 1.577 49.0      F     0
## 6     4 1.418 49.0      F     0
## 7     4 1.569 50.0      F     0
## 8     5 1.196 46.5      F     0
## 9     5 1.400 49.0      F     0
## 10    5 1.282 49.0      F     0
## 11    5 1.343 50.0      F     0
## 12    5 1.146 50.0      F     0
## 13    5 1.092 50.0      F     0
## 14    5 1.539 50.0      F     0
## 15    5 1.704 51.0      F     0
## 16    5 1.589 51.0      F     0
## 17    5 1.612 52.0      F     0
## 18    5 1.536 52.0      F     0
## 19    5 0.791 52.0      F     0
## 20    5 1.256 52.5      F     0
## 21    5 1.552 54.0      F     0
## 22    6 1.481 51.0      F     0
## 23    6 1.523 51.0      F     0
## 24    6 1.338 51.5      F     0
## 25    6 1.343 52.0      F     0
## 26    6 1.602 53.0      F     0
## 27    6 1.878 53.0      F     0
## 28    6 1.719 53.0      F     0
## 29    6 1.695 53.0      F     0
## 30    6 1.672 54.0      F     0
## 31    6 1.697 55.0      F     0
## 32    6 1.796 55.0      F     0
## 33    6 1.535 55.0      F     0
## 34    6 2.102 55.5      F     0
## 35    6 1.415 56.0      F     0
## 36    6 1.919 58.0      F     0
## 37    7 1.603 51.0      F     0
## 38    7 1.609 51.5      F     0
## 39    7 1.473 52.5      F     0
## 40    7 1.877 52.5      F     0
## 41    7 1.935 52.5      F     0
## 42    7 1.726 53.0      F     0
## 43    7 1.415 53.5      F     0
## 44    7 1.829 54.0      F     0
## 45    7 1.461 54.0      F     0
## 46    7 1.690 54.0      F     0
## 47    7 1.720 54.5      F     0
## 48    7 1.698 54.5      F     0
## 49    7 1.827 54.5      F     0
## 50    7 1.750 55.0      F     0
## 51    7 1.370 55.0      F     0
## 52    7 1.640 55.0      F     0
## 53    7 1.631 55.5      F     0
## 54    7 2.371 55.5      F     0
## 55    7 1.728 56.5      F     0
## 56    7 2.111 57.0      F     0
## 57    7 2.095 57.0      F     0
## 58    7 1.495 57.0      F     0
## 59    7 2.093 57.5      F     0
## 60    7 2.002 57.5      F     0
## 61    7 1.917 58.0      F     0
## 62    7 2.366 58.0      F     0
## 63    7 2.564 58.0      F     0
## 64    7 1.742 58.5      F     0
## 65    7 2.419 60.0      F     0
## 66    8 1.292 52.0      F     0
## 67    8 1.758 52.0      F     0
## 68    8 1.344 52.5      F     0
## 69    8 1.512 53.0      F     0
## 70    8 1.872 56.5      F     0
## 71    8 1.335 56.5      F     0
## 72    8 1.844 56.5      F     0
## 73    8 1.999 56.5      F     0
## 74    8 1.931 57.0      F     0
## 75    8 2.333 57.0      F     0
## 76    8 1.698 57.5      F     0
## 77    8 2.015 57.5      F     0
## 78    8 2.531 58.0      F     0
## 79    8 2.293 58.0      F     0
## 80    8 1.953 58.0      F     0
## 81    8 1.987 58.5      F     0
## 82    8 2.193 58.5      F     0
## 83    8 1.780 58.5      F     0
## 84    8 1.556 58.5      F     0
## 85    8 2.175 59.0      F     0
## 86    8 1.697 59.0      F     0
## 87    8 2.135 59.0      F     0
## 88    8 2.335 59.0      F     0
## 89    8 2.639 59.5      F     0
## 90    8 2.145 59.5      F     0
## 91    8 2.980 60.0      F     0
## 92    8 2.673 60.0      F     0
## 93    8 2.481 60.0      F     0
## 94    8 2.215 60.0      F     0
## 95    8 2.388 60.0      F     0
## 96    8 2.069 60.0      F     0
## 97    8 2.328 60.0      F     0
## 98    8 2.341 60.5      F     0
## 99    8 2.336 61.0      F     0
## 100   8 2.458 61.0      F     0
## 101   8 2.358 61.0      F     0
## 102   8 2.288 61.5      F     0
## 103   8 2.187 61.5      F     0
## 104   8 2.382 62.0      F     0
## 105   8 2.709 62.5      F     0
## 106   8 2.144 63.0      F     0
## 107   8 2.993 63.0      F     0
## 108   8 2.476 63.0      F     0
## 109   8 2.665 64.0      F     0
## 110   8 2.305 64.5      F     0
## 111   8 1.724 67.5      F     0
## 112   9 2.040 55.5      F     0
## 113   9 1.886 56.0      F     0
## 114   9 1.947 56.5      F     0
## 115   9 1.708 57.0      F     0
## 116   9 2.076 57.0      F     0
## 117   9 2.320 57.0      F     0
## 118   9 1.591 57.0      F     0
## 119   9 1.606 57.5      F     0
## 120   9 2.166 57.5      F     0
## 121   9 1.933 58.0      F     0
## 122   9 2.259 58.5      F     0
## 123   9 2.091 58.5      F     0
## 124   9 2.130 59.0      F     0
## 125   9 2.529 59.0      F     0
## 126   9 1.969 59.0      F     0
## 127   9 1.912 59.0      F     0
## 128   9 2.316 59.5      F     0
## 129   9 2.182 59.5      F     0
## 130   9 2.688 59.5      F     0
## 131   9 1.942 60.0      F     0
## 132   9 2.100 60.0      F     0
## 133   9 3.135 60.0      F     0
## 134   9 2.851 60.0      F     0
## 135   9 2.455 60.0      F     0
## 136   9 2.560 60.5      F     0
## 137   9 2.574 60.5      F     0
## 138   9 2.592 60.5      F     0
## 139   9 2.463 61.0      F     0
## 140   9 2.797 61.5      F     0
## 141   9 3.029 61.5      F     0
## 142   9 2.442 61.5      F     0
## 143   9 1.754 61.5      F     0
## 144   9 2.631 62.0      F     0
## 145   9 3.016 62.5      F     0
## 146   9 2.056 63.0      F     0
## 147   9 2.639 63.0      F     0
## 148   9 2.850 63.0      F     0
## 149   9 3.004 64.0      F     0
## 150   9 2.485 64.0      F     0
## 151   9 2.487 64.0      F     0
## 152   9 2.048 64.5      F     0
## 153   9 2.988 65.0      F     0
## 154   9 3.223 65.0      F     0
## 155   9 3.042 66.0      F     0
## 156  10 1.823 57.0      F     0
## 157  10 1.458 57.0      F     0
## 158  10 2.250 58.0      F     0
## 159  10 2.175 58.0      F     0
## 160  10 2.250 58.0      F     0
## 161  10 2.358 59.0      F     0
## 162  10 3.132 59.5      F     0
## 163  10 2.864 60.0      F     0
## 164  10 2.504 60.0      F     0
## 165  10 3.050 60.0      F     0
## 166  10 2.520 60.5      F     0
## 167  10 2.356 60.5      F     0
## 168  10 2.642 61.0      F     0
## 169  10 2.891 61.0      F     0
## 170  10 2.287 61.0      F     0
## 171  10 2.862 61.0      F     0
## 172  10 3.166 61.5      F     0
## 173  10 2.813 61.5      F     0
## 174  10 2.688 62.0      F     0
## 175  10 3.086 62.0      F     0
## 176  10 2.838 63.0      F     0
## 177  10 2.365 63.5      F     0
## 178  10 2.568 63.5      F     0
## 179  10 2.673 64.5      F     0
## 180  10 3.305 65.0      F     0
## 181  10 2.435 65.0      F     0
## 182  10 3.048 65.5      F     0
## 183  10 3.183 65.5      F     0
## 184  10 3.073 66.0      F     0
## 185  10 2.691 67.0      F     0
## 186  11 2.170 58.0      F     0
## 187  11 2.346 59.0      F     0
## 188  11 2.318 59.0      F     0
## 189  11 2.491 59.0      F     0
## 190  11 2.762 60.0      F     0
## 191  11 2.458 60.0      F     0
## 192  11 2.866 60.5      F     0
## 193  11 2.140 60.5      F     0
## 194  11 2.362 61.0      F     0
## 195  11 2.386 61.5      F     0
## 196  11 3.022 61.5      F     0
## 197  11 2.689 61.5      F     0
## 198  11 2.633 62.0      F     0
## 199  11 2.542 62.0      F     0
## 200  11 2.354 62.0      F     0
## 201  11 2.974 62.0      F     0
## 202  11 2.501 62.0      F     0
## 203  11 2.822 62.0      F     0
## 204  11 2.735 62.5      F     0
## 205  11 2.827 62.5      F     0
## 206  11 2.562 62.5      F     0
## 207  11 2.665 63.0      F     0
## 208  11 3.171 63.0      F     0
## 209  11 2.578 63.0      F     0
## 210  11 2.081 63.0      F     0
## 211  11 3.258 63.0      F     0
## 212  11 2.563 63.0      F     0
## 213  11 3.411 63.5      F     0
## 214  11 3.011 64.0      F     0
## 215  11 3.515 64.0      F     0
## 216  11 3.223 64.5      F     0
## 217  11 3.654 65.0      F     0
## 218  11 2.606 65.0      F     0
## 219  11 2.754 65.5      F     0
## 220  11 3.236 66.0      F     0
## 221  11 3.490 67.0      F     0
## 222  11 3.774 67.0      F     0
## 223  11 3.023 67.5      F     0
## 224  11 3.681 68.0      F     0
## 225  12 3.079 60.0      F     0
## 226  12 3.058 60.5      F     0
## 227  12 2.417 61.0      F     0
## 228  12 3.222 61.0      F     0
## 229  12 2.347 61.5      F     0
## 230  12 2.556 62.0      F     0
## 231  12 2.868 62.0      F     0
## 232  12 3.403 62.0      F     0
## 233  12 2.866 62.0      F     0
## 234  12 3.035 62.0      F     0
## 235  12 2.605 62.5      F     0
## 236  12 2.841 63.0      F     0
## 237  12 2.751 63.0      F     0
## 238  12 2.569 63.0      F     0
## 239  12 2.579 63.0      F     0
## 240  12 2.752 63.5      F     0
## 241  12 3.082 63.5      F     0
## 242  12 3.001 63.5      F     0
## 243  12 2.889 64.0      F     0
## 244  12 3.501 64.5      F     0
## 245  12 3.082 64.5      F     0
## 246  12 2.714 65.5      F     0
## 247  12 3.519 65.5      F     0
## 248  12 3.341 65.5      F     0
## 249  12 3.255 66.0      F     0
## 250  13 2.704 61.0      F     0
## 251  13 3.141 61.0      F     0
## 252  13 2.646 61.5      F     0
## 253  13 3.060 61.5      F     0
## 254  13 2.819 62.0      F     0
## 255  13 3.056 63.0      F     0
## 256  13 2.449 63.0      F     0
## 257  13 3.816 63.5      F     0
## 258  13 3.577 63.5      F     0
## 259  13 3.147 64.0      F     0
## 260  13 2.434 65.4      F     0
## 261  13 3.331 65.5      F     0
## 262  13 3.255 66.5      F     0
## 263  13 3.745 68.0      F     0
## 264  14 2.891 62.0      F     0
## 265  14 3.169 64.0      F     0
## 266  14 2.934 64.0      F     0
## 267  14 2.997 64.5      F     0
## 268  14 3.395 67.0      F     0
## 269  14 2.538 71.0      F     0
## 270  15 2.887 63.0      F     0
## 271  15 2.635 64.0      F     0
## 272  15 3.211 66.5      F     0
## 273  16 2.981 66.0      F     0
## 274  16 3.387 66.5      F     0
## 275  16 3.674 67.5      F     0
## 276  17 3.500 62.0      F     0
## 277  18 2.853 60.0      F     0
## 278  18 3.082 64.5      F     0
## 279  18 2.906 66.0      F     0
## 280   3 1.404 51.5      M     0
## 281   4 0.796 47.0      M     0
## 282   4 1.004 48.0      M     0
## 283   4 1.789 52.0      M     0
## 284   5 1.472 50.0      M     0
## 285   5 2.115 50.0      M     0
## 286   5 1.359 50.5      M     0
## 287   5 1.776 51.0      M     0
## 288   5 1.452 51.0      M     0
## 289   5 1.930 51.0      M     0
## 290   5 1.755 52.0      M     0
## 291   5 1.514 52.0      M     0
## 292   5 1.580 52.5      M     0
## 293   5 1.858 53.0      M     0
## 294   5 1.819 53.0      M     0
## 295   5 2.017 54.5      M     0
## 296   5 1.808 55.5      M     0
## 297   5 1.971 58.0      M     0
## 298   6 1.536 48.0      M     0
## 299   6 1.423 49.5      M     0
## 300   6 1.427 49.5      M     0
## 301   6 1.713 50.5      M     0
## 302   6 1.431 51.0      M     0
## 303   6 1.624 51.5      M     0
## 304   6 1.572 52.0      M     0
## 305   6 1.666 52.0      M     0
## 306   6 1.527 52.5      M     0
## 307   6 1.826 52.5      M     0
## 308   6 1.338 53.0      M     0
## 309   6 1.348 53.0      M     0
## 310   6 1.715 53.0      M     0
## 311   6 1.691 53.0      M     0
## 312   6 1.634 54.0      M     0
## 313   6 1.699 54.0      M     0
## 314   6 1.650 55.0      M     0
## 315   6 1.718 55.0      M     0
## 316   6 1.979 56.0      M     0
## 317   6 2.104 56.5      M     0
## 318   6 1.747 57.5      M     0
## 319   6 2.262 57.5      M     0
## 320   7 1.165 47.0      M     0
## 321   7 1.826 51.0      M     0
## 322   7 1.253 52.0      M     0
## 323   7 1.932 53.0      M     0
## 324   7 1.658 53.0      M     0
## 325   7 2.158 53.5      M     0
## 326   7 1.790 53.5      M     0
## 327   7 1.624 54.0      M     0
## 328   7 1.649 54.0      M     0
## 329   7 2.056 54.0      M     0
## 330   7 1.682 55.0      M     0
## 331   7 2.219 55.0      M     0
## 332   7 1.796 55.0      M     0
## 333   7 1.789 56.0      M     0
## 334   7 2.046 56.0      M     0
## 335   7 2.550 56.0      M     0
## 336   7 2.135 56.0      M     0
## 337   7 1.920 56.5      M     0
## 338   7 1.612 56.5      M     0
## 339   7 1.611 57.5      M     0
## 340   7 2.084 58.0      M     0
## 341   7 2.220 58.0      M     0
## 342   7 1.905 58.0      M     0
## 343   7 2.535 59.5      M     0
## 344   7 2.578 62.5      M     0
## 345   8 1.744 52.5      M     0
## 346   8 1.675 53.0      M     0
## 347   8 1.759 53.0      M     0
## 348   8 1.624 53.0      M     0
## 349   8 1.735 54.0      M     0
## 350   8 2.069 54.0      M     0
## 351   8 1.703 54.5      M     0
## 352   8 1.794 54.5      M     0
## 353   8 2.071 55.0      M     0
## 354   8 1.523 55.0      M     0
## 355   8 1.562 55.0      M     0
## 356   8 2.010 55.0      M     0
## 357   8 1.897 55.5      M     0
## 358   8 2.016 56.0      M     0
## 359   8 1.657 56.0      M     0
## 360   8 1.547 57.0      M     0
## 361   8 2.004 57.0      M     0
## 362   8 1.962 57.0      M     0
## 363   8 2.090 57.0      M     0
## 364   8 2.303 57.0      M     0
## 365   8 2.226 57.0      M     0
## 366   8 2.500 57.0      M     0
## 367   8 1.429 57.5      M     0
## 368   8 2.094 57.5      M     0
## 369   8 2.258 58.0      M     0
## 370   8 2.354 58.5      M     0
## 371   8 2.420 59.0      M     0
## 372   8 1.940 59.0      M     0
## 373   8 2.631 59.0      M     0
## 374   8 2.631 59.0      M     0
## 375   8 1.991 59.5      M     0
## 376   8 2.435 59.5      M     0
## 377   8 2.123 60.0      M     0
## 378   8 2.118 60.5      M     0
## 379   8 2.732 60.5      M     0
## 380   8 2.681 60.5      M     0
## 381   8 2.211 63.0      M     0
## 382   8 2.503 63.0      M     0
## 383   8 2.927 63.5      M     0
## 384   9 1.558 53.0      M     0
## 385   9 1.716 55.5      M     0
## 386   9 1.895 57.0      M     0
## 387   9 2.570 57.0      M     0
## 388   9 2.420 57.0      M     0
## 389   9 2.119 57.0      M     0
## 390   9 1.869 57.0      M     0
## 391   9 2.069 58.0      M     0
## 392   9 1.751 58.0      M     0
## 393   9 1.773 58.5      M     0
## 394   9 2.135 58.5      M     0
## 395   9 2.301 58.5      M     0
## 396   9 2.352 59.0      M     0
## 397   9 2.725 59.0      M     0
## 398   9 2.457 59.0      M     0
## 399   9 2.090 59.5      M     0
## 400   9 2.973 59.5      M     0
## 401   9 2.803 59.5      M     0
## 402   9 2.348 60.0      M     0
## 403   9 2.715 60.0      M     0
## 404   9 2.164 60.0      M     0
## 405   9 1.855 60.0      M     0
## 406   9 2.571 60.5      M     0
## 407   9 2.076 60.5      M     0
## 408   9 2.196 61.0      M     0
## 409   9 2.230 61.0      M     0
## 410   9 2.604 61.5      M     0
## 411   9 2.659 61.5      M     0
## 412   9 2.165 61.5      M     0
## 413   9 2.717 61.5      M     0
## 414   9 2.457 61.5      M     0
## 415   9 2.833 61.5      M     0
## 416   9 3.556 62.0      M     0
## 417   9 2.126 62.0      M     0
## 418   9 2.042 62.0      M     0
## 419   9 2.798 62.0      M     0
## 420   9 2.588 63.0      M     0
## 421   9 2.650 63.5      M     0
## 422   9 2.246 63.5      M     0
## 423   9 2.460 64.0      M     0
## 424   9 2.923 64.0      M     0
## 425   9 2.964 64.5      M     0
## 426   9 3.114 64.5      M     0
## 427   9 2.893 64.5      M     0
## 428   9 2.871 65.0      M     0
## 429   9 3.239 65.0      M     0
## 430   9 3.000 65.5      M     0
## 431   9 3.681 68.0      M     0
## 432   9 3.842 69.0      M     0
## 433  10 1.873 52.5      M     0
## 434  10 1.811 57.0      M     0
## 435  10 1.665 57.0      M     0
## 436  10 1.858 58.0      M     0
## 437  10 2.100 58.0      M     0
## 438  10 2.094 58.5      M     0
## 439  10 1.858 59.0      M     0
## 440  10 2.132 59.0      M     0
## 441  10 2.901 59.5      M     0
## 442  10 2.391 59.5      M     0
## 443  10 2.646 60.0      M     0
## 444  10 2.246 60.5      M     0
## 445  10 2.201 60.5      M     0
## 446  10 2.481 61.0      M     0
## 447  10 2.216 61.0      M     0
## 448  10 2.364 61.0      M     0
## 449  10 2.341 61.0      M     0
## 450  10 2.352 61.5      M     0
## 451  10 2.561 62.0      M     0
## 452  10 1.937 62.0      M     0
## 453  10 3.007 62.0      M     0
## 454  10 3.127 62.0      M     0
## 455  10 2.770 62.0      M     0
## 456  10 2.292 63.0      M     0
## 457  10 3.354 63.0      M     0
## 458  10 3.456 63.0      M     0
## 459  10 2.328 64.0      M     0
## 460  10 2.855 64.5      M     0
## 461  10 3.110 64.5      M     0
## 462  10 2.592 65.0      M     0
## 463  10 2.545 65.0      M     0
## 464  10 3.200 65.0      M     0
## 465  10 3.090 65.0      M     0
## 466  10 2.720 65.5      M     0
## 467  10 2.758 65.5      M     0
## 468  10 3.203 66.0      M     0
## 469  10 3.111 66.0      M     0
## 470  10 3.251 66.0      M     0
## 471  10 2.608 66.0      M     0
## 472  10 2.696 66.0      M     0
## 473  10 2.581 66.0      M     0
## 474  10 3.489 66.5      M     0
## 475  10 3.329 68.0      M     0
## 476  10 3.795 68.5      M     0
## 477  10 3.350 69.0      M     0
## 478  10 4.591 70.0      M     0
## 479  11 2.498 60.0      M     0
## 480  11 2.465 60.0      M     0
## 481  11 2.387 60.5      M     0
## 482  11 3.058 61.0      M     0
## 483  11 2.812 61.0      M     0
## 484  11 2.417 62.5      M     0
## 485  11 2.887 62.5      M     0
## 486  11 3.206 63.5      M     0
## 487  11 2.524 64.0      M     0
## 488  11 2.659 64.0      M     0
## 489  11 2.957 64.5      M     0
## 490  11 3.108 64.5      M     0
## 491  11 2.463 64.5      M     0
## 492  11 3.587 64.5      M     0
## 493  11 2.123 65.0      M     0
## 494  11 3.425 65.5      M     0
## 495  11 3.247 65.5      M     0
## 496  11 3.320 65.5      M     0
## 497  11 2.928 65.5      M     0
## 498  11 3.847 66.0      M     0
## 499  11 3.280 66.0      M     0
## 500  11 3.470 66.5      M     0
## 501  11 4.065 66.5      M     0
## 502  11 2.993 66.5      M     0
## 503  11 4.007 67.0      M     0
## 504  11 3.583 67.0      M     0
## 505  11 4.073 67.0      M     0
## 506  11 2.894 67.0      M     0
## 507  11 4.130 67.0      M     0
## 508  11 3.515 67.5      M     0
## 509  11 3.111 67.5      M     0
## 510  11 4.324 67.5      M     0
## 511  11 3.078 67.5      M     0
## 512  11 3.596 68.0      M     0
## 513  11 3.845 68.5      M     0
## 514  11 2.884 69.0      M     0
## 515  11 4.593 69.0      M     0
## 516  11 2.785 69.0      M     0
## 517  11 2.988 70.0      M     0
## 518  11 3.977 70.5      M     0
## 519  11 3.369 70.5      M     0
## 520  11 3.222 72.0      M     0
## 521  12 2.332 57.0      M     0
## 522  12 1.916 60.5      M     0
## 523  12 3.231 63.0      M     0
## 524  12 2.241 64.0      M     0
## 525  12 2.913 64.0      M     0
## 526  12 3.530 64.0      M     0
## 527  12 2.971 64.5      M     0
## 528  12 4.080 64.5      M     0
## 529  12 2.499 65.0      M     0
## 530  12 2.935 65.5      M     0
## 531  12 3.692 67.0      M     0
## 532  12 4.411 68.0      M     0
## 533  12 3.924 68.0      M     0
## 534  12 4.393 68.5      M     0
## 535  12 3.791 68.5      M     0
## 536  12 4.073 68.5      M     0
## 537  12 2.752 68.5      M     0
## 538  12 2.822 69.5      M     0
## 539  12 5.224 70.0      M     0
## 540  12 3.279 70.5      M     0
## 541  12 3.529 70.5      M     0
## 542  12 4.550 71.0      M     0
## 543  12 4.831 71.0      M     0
## 544  12 4.203 71.0      M     0
## 545  12 4.720 71.5      M     0
## 546  13 2.531 61.0      M     0
## 547  13 2.976 65.5      M     0
## 548  13 3.906 67.0      M     0
## 549  13 3.994 67.0      M     0
## 550  13 3.887 67.5      M     0
## 551  13 3.089 67.5      M     0
## 552  13 3.549 68.0      M     0
## 553  13 4.305 68.5      M     0
## 554  13 4.448 69.0      M     0
## 555  13 4.336 69.5      M     0
## 556  13 3.193 70.0      M     0
## 557  13 4.232 70.5      M     0
## 558  13 3.984 71.0      M     0
## 559  13 4.877 73.0      M     0
## 560  13 4.225 74.0      M     0
## 561  13 5.083 74.0      M     0
## 562  14 3.436 62.5      M     0
## 563  14 3.381 63.0      M     0
## 564  14 3.680 67.0      M     0
## 565  14 3.806 68.0      M     0
## 566  14 3.741 68.5      M     0
## 567  14 4.683 68.5      M     0
## 568  14 3.585 70.0      M     0
## 569  14 3.780 70.0      M     0
## 570  14 4.111 71.0      M     0
## 571  14 4.842 72.0      M     0
## 572  14 4.273 72.5      M     0
## 573  14 4.271 72.5      M     0
## 574  15 3.731 67.0      M     0
## 575  15 4.279 67.5      M     0
## 576  15 5.793 69.0      M     0
## 577  15 4.284 70.0      M     0
## 578  15 4.500 70.0      M     0
## 579  15 3.985 71.0      M     0
## 580  16 4.299 66.0      M     0
## 581  16 4.504 72.0      M     0
## 582  16 3.645 73.5      M     0
## 583  17 4.429 70.0      M     0
## 584  17 3.960 70.0      M     0
## 585  17 5.638 70.0      M     0
## 586  17 4.724 70.5      M     0
## 587  17 5.633 73.0      M     0
## 588  18 4.220 68.0      M     0
## 589  19 5.102 72.0      M     0
## 590  10 2.975 63.0      F     1
## 591  10 3.038 65.0      F     1
## 592  10 2.387 66.0      F     1
## 593  10 3.413 66.0      F     1
## 594  11 3.120 61.0      F     1
## 595  11 3.169 62.5      F     1
## 596  11 3.102 64.0      F     1
## 597  11 3.069 65.0      F     1
## 598  11 2.953 67.0      F     1
## 599  11 3.104 67.5      F     1
## 600  12 2.759 61.5      F     1
## 601  12 2.384 63.5      F     1
## 602  12 3.186 67.0      F     1
## 603  12 3.835 69.5      F     1
## 604  13 3.208 61.0      F     1
## 605  13 3.152 62.0      F     1
## 606  13 2.599 62.5      F     1
## 607  13 3.785 63.0      F     1
## 608  13 3.297 65.0      F     1
## 609  13 3.297 65.0      F     1
## 610  13 3.078 66.0      F     1
## 611  13 2.677 67.0      F     1
## 612  13 3.086 67.5      F     1
## 613  13 2.216 68.0      F     1
## 614  14 3.428 64.0      F     1
## 615  14 3.074 65.0      F     1
## 616  14 2.236 66.0      F     1
## 617  15 2.278 60.0      F     1
## 618  15 2.198 62.0      F     1
## 619  15 2.264 63.0      F     1
## 620  15 3.004 64.0      F     1
## 621  15 3.122 64.0      F     1
## 622  15 2.679 66.0      F     1
## 623  15 3.330 68.5      F     1
## 624  16 2.608 62.0      F     1
## 625  16 2.903 63.0      F     1
## 626  16 2.795 63.0      F     1
## 627  19 3.345 65.5      F     1
## 628  19 3.519 66.0      F     1
## 629   9 1.953 58.0      M     1
## 630  10 3.498 68.0      M     1
## 631  11 1.694 60.0      M     1
## 632  11 3.339 68.5      M     1
## 633  11 4.637 72.0      M     1
## 634  12 2.304 66.5      M     1
## 635  12 3.343 68.0      M     1
## 636  12 3.751 72.0      M     1
## 637  13 4.756 68.0      M     1
## 638  13 4.789 69.0      M     1
## 639  13 4.045 69.0      M     1
## 640  14 2.276 66.0      M     1
## 641  14 4.763 68.0      M     1
## 642  14 4.309 69.0      M     1
## 643  14 3.957 72.0      M     1
## 644  15 3.799 66.5      M     1
## 645  15 3.727 68.0      M     1
## 646  15 4.506 71.0      M     1
## 647  16 4.270 67.0      M     1
## 648  16 3.688 68.0      M     1
## 649  16 4.070 69.5      M     1
## 650  16 4.872 72.0      M     1
## 651  17 3.082 67.0      M     1
## 652  17 3.406 69.0      M     1
## 653  18 4.086 67.0      M     1
## 654  18 4.404 70.5      M     1
names(lungcap)
## [1] "Age"    "FEV"    "Ht"     "Gender" "Smoke"
class(Gender)
## [1] "factor"
head(Gender)
## [1] F F F F F F
## Levels: F M
femalelungcap <-  FEV[Gender=="F"]
stem(femalelungcap, scale=2)
## 
##   The decimal point is 1 digit(s) to the left of the |
## 
##    7 | 9
##    8 | 4
##    9 | 
##   10 | 79
##   11 | 05
##   12 | 0689
##   13 | 4444479
##   14 | 02226678
##   15 | 012444567899
##   16 | 001113479
##   17 | 00000012223345568
##   18 | 023347889
##   19 | 12233445579
##   20 | 00245678899
##   21 | 0001334457777899
##   22 | 022455668999
##   23 | 122233444555666677788999
##   24 | 223445666688999
##   25 | 002334466666777889
##   26 | 011133444457777889999
##   27 | 011455566
##   28 | 00122344555667779999
##   29 | 0135788899
##   30 | 000012223444556667778888899
##   31 | 002234455777789
##   32 | 112224666
##   33 | 00133459
##   34 | 001139
##   35 | 002228
##   36 | 578
##   37 | 579
##   38 | 24

Stacked and Group Bar Chart

class(Smoke)
## [1] "integer"
as.factor(Smoke)
##   [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
##  [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
##  [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [112] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [149] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [186] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [223] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [260] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [297] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [334] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [371] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [408] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [445] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [482] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [519] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [556] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1
## [593] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
## [630] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
## Levels: 0 1
Table1 <- table(Smoke,Gender)
Table1
##      Gender
## Smoke   F   M
##     0 279 310
##     1  39  26
barplot(Table1)

barplot(Table1, beside=T,legend.text=T)

barplot(Table1, beside=T,legend.text=c("Non-smoker","Smoker"), main="Gender and Smoking", xlab="Gender",las=1, col=c(2,5))

mosaicplot(Table1,legend.text=c("Non-smoker","Smoker"), main="Gender and Smoking", xlab="Gender",las=1, col=c(2,5))

Scatterplots

class(Age)
## [1] "integer"
names(lungcap)
## [1] "Age"    "FEV"    "Ht"     "Gender" "Smoke"
class(Ht)
## [1] "numeric"
summary(Ht)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   46.00   57.00   61.50   61.14   65.50   74.00
cor(Age, Ht)
## [1] 0.7919436
plot(Age, Ht, main="Scatterplot of Age and Height", xlab="Age",ylab="Height", las=1,xlim=c(0,20), pch=8, col=2)
abline(lm(Ht~Age),col=4,lwd=2)
lines(smooth.spline(Age,Ht))
lines(smooth.spline(Age,Ht),lty=2,lwd=5)

Calculating Mean, Standard Deviation, Frequencies in R

summary(FEV)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.791   1.981   2.547   2.637   3.119   5.793
table(Smoke)/length(Smoke)
## Smoke
##          0          1 
## 0.90061162 0.09938838
table(Smoke, Gender)
##      Gender
## Smoke   F   M
##     0 279 310
##     1  39  26
mean(FEV)
## [1] 2.63678
mean(FEV, trim=0.10)
## [1] 2.572078
median(FEV)
## [1] 2.5475
var(FEV)
## [1] 0.7517915
sd(FEV)
## [1] 0.8670591
sqrt(var(FEV))
## [1] 0.8670591
sd(FEV)^2
## [1] 0.7517915
min(FEV)
## [1] 0.791
max(FEV)
## [1] 5.793
range(FEV)
## [1] 0.791 5.793
quantile(FEV, probs=0.90)
##   90% 
## 3.813
quantile(FEV, probs=c(0.2,0.5,0.9,1))
##    20%    50%    90%   100% 
## 1.8506 2.5475 3.8130 5.7930
sum(FEV)
## [1] 1724.454
cor(FEV,Age)
## [1] 0.756459
cor(FEV,Age, method="spearman")
## [1] 0.7984229
cov(FEV,Age)
## [1] 1.93747
var(FEV, Age)
## [1] 1.93747
summary(FEV)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.791   1.981   2.547   2.637   3.119   5.793
summary(Smoke)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 0.00000 0.00000 0.00000 0.09939 0.00000 1.00000
summary(Gender)
##   F   M 
## 318 336
summary(lungcap)
##       Age              FEV              Ht        Gender      Smoke        
##  Min.   : 3.000   Min.   :0.791   Min.   :46.00   F:318   Min.   :0.00000  
##  1st Qu.: 8.000   1st Qu.:1.981   1st Qu.:57.00   M:336   1st Qu.:0.00000  
##  Median :10.000   Median :2.547   Median :61.50           Median :0.00000  
##  Mean   : 9.931   Mean   :2.637   Mean   :61.14           Mean   :0.09939  
##  3rd Qu.:12.000   3rd Qu.:3.119   3rd Qu.:65.50           3rd Qu.:0.00000  
##  Max.   :19.000   Max.   :5.793   Max.   :74.00           Max.   :1.00000

How to Modify and Customize Plots in R

plot(Age,Ht, main="Scatterplot", cex=0.5,cex.main=2,cex.lab=1.5,cex.axis=0.7)

plot(Age,Ht, main="Scatterplot")

plot(Age,Ht, main="Scatterplot", font.main=3)

plot(Age,Ht, main="Scatterplot", font.main=4)

plot(Age,Ht, main="Scatterplot", font.main=4, font.lab=2)

plot(Age,Ht, main="Scatterplot", font.main=4, font.lab=2, font.axis=3)

plot(Age,Ht, main="Scatterplot")

plot(Age,Ht, main="Scatterplot",col=5,col.main=4,col.lab=2,col.axis=3)

plot(Age,Ht, main="Scatterplot")

plot(Age,Ht, main="Scatterplot", pch=2)

plot(Age,Ht, main="Scatterplot", pch="w")
abline(lm(Ht~Age), col=4,lty=2,lwd=6)

plot(Age[Gender=="M"],Ht[Gender=="M"],col=4,pch="m")

plot(Age[Gender=="M"],Ht[Gender=="M"],col=4,pch="m", xlab="Age",ylab="Height", main="Height vs Age")
points(Age[Gender=="F"],Ht[Gender=="F"], col=6,pch="f")

par(mfrow=c(1,2))
plot(Age[Gender=="M"],Ht[Gender=="M"], xlab="Age",ylab="Height", main="Height vs Age for Males",xlim=c(0,20),ylim=c(45,75))
plot(Age[Gender=="F"],Ht[Gender=="F"], xlab="Age",ylab="Height", main="Height vs Age for Females",xlim=c(0,20),ylim=c(45,75))

par(mfrow=c(1,1))
plot(Age,Ht, main="TITLE")

plot(Age,Ht, main="TITLE",axes=F)
axis(side=1,at=c(5,10,15), labels=c("sev","mean","15"))
axis(side=2,at=c(50,60,70), labels=c(50,60,70))
box()
axis(side=4, at=c(45,55,65,75), labels=c(45,55,65,75))

par
## function (..., no.readonly = FALSE) 
## {
##     .Pars.readonly <- c("cin", "cra", "csi", "cxy", "din", "page")
##     single <- FALSE
##     args <- list(...)
##     if (!length(args)) 
##         args <- as.list(if (no.readonly) 
##             .Pars[-match(.Pars.readonly, .Pars)]
##         else .Pars)
##     else {
##         if (all(unlist(lapply(args, is.character)))) 
##             args <- as.list(unlist(args))
##         if (length(args) == 1) {
##             if (is.list(args[[1L]]) || is.null(args[[1L]])) 
##                 args <- args[[1L]]
##             else if (is.null(names(args))) 
##                 single <- TRUE
##         }
##     }
##     value <- .External2(C_par, args)
##     if (single) 
##         value <- value[[1L]]
##     if (!is.null(names(args))) 
##         invisible(value)
##     else value
## }
## <bytecode: 0x00000219cb1be110>
## <environment: namespace:graphics>

Add and Customize Text in Plots with R

plot(Age,FEV, main="Scatterplot of Lung Capacity vs Age", las=1)
cor(Age,FEV)
## [1] 0.756459
text(x=5,y=4, label= "r = 0.756", adj=0)

plot(Age,FEV, main="Scatterplot of Lung Capacity vs Age", las=1)
text(x=3,y=5.5, adj=0, label= "r = 0.756", cex=0.5, col=4)

plot(Age,FEV, main="Scatterplot of Lung Capacity vs Age", las=1)
text(x=3,y=5.5, adj=0, label= "r = 0.756", cex=1, col=4, font=4)
abline(h=mean(FEV), col=2,lwd=2)
text(x=4,y=4.5, adj=0,label="Mean Lung Cap",cex=1, col=2)

plot(Age,FEV, main="Scatterplot of Lung Capacity vs Age", las=1)
mtext(text="r = 0.756", side=1)
mtext(text="r = 0.756", side=2)
mtext(text="r = 0.756", side=3)
mtext(text="r = 0.756", side=4)
mtext(text="r = 0.756", side=1, adj=0)
mtext(text="r = 0.756", side=1, adj=0.75)
mtext(text="r = 0.756", side=1,adj=1)

plot(Age,FEV, main="Scatterplot of Lung Capacity vs Age", las=1)
mtext(text="r = 0.756", side=3,adj=1, col=4,cex=1.25, font=4)

Add and Customize Legends to Plots in R

plot(Age[Smoke==0],FEV[Smoke==0],main="Lung Capacity vs Age for Smoke/Non Smoke", col=4, xlab="Age", ylab="Lung Cap")
points(Age[Smoke==1],FEV[Smoke==1], col="red")
legend(x=5,y=4, legend=c("Non smoke", "Smoke"),fill=c(4,2))

plot(Age[Smoke==0],FEV[Smoke==0],main="Lung Capacity vs Age for Smoke/Non Smoke", col=4, xlab="Age", ylab="Lung Cap", pch=16)
points(Age[Smoke==1],FEV[Smoke==1], col="red", pch=17)
legend(x=5,y=5, legend=c("Non smoke", "Smoke"),col=c(4,2), pch=c(16,17), bty="n")

plot(Age[Smoke==0],FEV[Smoke==0],main="Lung Capacity vs Age for Smoke/Non Smoke", col=4, xlab="Age", ylab="Lung Cap", pch=16)
points(Age[Smoke==1],FEV[Smoke==1], col="red", pch=17)
lines(smooth.spline(Age[Smoke==0],FEV[Smoke==0]),col=4, lwd=4)
lines(smooth.spline(Age[Smoke==1],FEV[Smoke==1]),col=2, lwd=4)
legend(x=5,y=5, legend=c("Non smoke", "Smoke"),col=c(4,2), lty=1, bty="n", lwd=3)

plot(Age[Smoke==0],FEV[Smoke==0],main="Lung Capacity vs Age for Smoke/Non Smoke", col=4, xlab="Age", ylab="Lung Cap", pch=16)
points(Age[Smoke==1],FEV[Smoke==1], col="red", pch=17)
lines(smooth.spline(Age[Smoke==0],FEV[Smoke==0]),col=4, lwd=4, lty=2)
lines(smooth.spline(Age[Smoke==1],FEV[Smoke==1]),col=2, lwd=4, lty=3)
legend(x=5,y=5, legend=c("Non smoke", "Smoke"),col=c(4,2), lty=c(2,3), bty="n", lwd=3)