Basic R (Child Growth)

Import Data

X= Age Y= Height

X <- c(5,6,4,5,6)
Y <- c(4,4.2,3.8,4,4.2)

X
## [1] 5 6 4 5 6
Y
## [1] 4.0 4.2 3.8 4.0 4.2

Plot

plot(X,Y)

Variables

a <- 2:7
#b <- seq(2,5, by=0.5)
c <- rep(1:2, each=3)
a
## [1] 2 3 4 5 6 7
c
## [1] 1 1 1 2 2 2

Arithmatic operation

p <- a+c
q <- a/c

p
## [1] 3 4 5 7 8 9
q
## [1] 2.0 3.0 4.0 2.5 3.0 3.5

Package (Car Data)

Package

library(dplyr)
## Warning: package 'dplyr' was built under R version 4.6.1
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## tidyverse

Data

Variables

mtcars$mpg
##  [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4
## [16] 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7
## [31] 15.0 21.4
mtcars$hp
##  [1] 110 110  93 110 175 105 245  62  95 123 123 180 180 180 205 215 230  66  52
## [20]  65  97 150 150 245 175  66  91 113 264 175 335 109

plot

plot(mtcars$hp, mtcars$mpg)

Read data (HBV Data)

Data

library(readxl)
df <- read_excel("C:/Users/user/Downloads/HBV_Data_All.xlsx")
#df

Variables

Statistics Fuction

mean(mtcars$mpg)
## [1] 20.09062
mean(mtcars$hp)
## [1] 146.6875
sd(mtcars$hp)
## [1] 68.56287

Data Structure (iris Data)

Data

data(iris)
iris

structure

str(iris)
## 'data.frame':    150 obs. of  5 variables:
##  $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
##  $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
##  $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
##  $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
##  $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
View(iris)

Data[row,col]

a1 <- iris[,1:2]
a2 <- iris[,4:5]

a1
a2
b1 <- iris[1:20,]
b2 <- iris[40:60,]

b1
b2

combind

cbind(a1,a2)
rbind(b1,b2)