# Gambar 2.9
Simpan = c(10,20,40,15,40)
Simpan
## [1] 10 20 40 15 40
# Gambar 2.10
Simpan = c(1000,2000,3000,4000,5000)
Simpan
## [1] 1000 2000 3000 4000 5000
# Gambar 2.12
Simpan = c(10,20,40,15,40)
Simpan[3]
## [1] 40
# Gambar 2.14
simpan = c(10,20,40,15,40)
simpan[4]
## [1] 15
# Gambar 2.16
simpan = c(10,20,40,15,40)
simpan[c(1,3,4)]
## [1] 10 40 15
simpan[2:4]
## [1] 20 40 15
# Gambar 2.18
simpan = c(10,20,40,15,40)
simpan
## [1] 10 20 40 15 40
simpan[3]=100
simpan[4]=10000
simpan
## [1]    10    20   100 10000    40
# Gambar 2.20
NILAI=c(10,40,45,30,80)
NILAI
## [1] 10 40 45 30 80
NILAI=NILAI[-3]
NILAI
## [1] 10 40 30 80
NILAI=NILAI[-4]
NILAI
## [1] 10 40 30
NILAI=NILAI[c(-1,-3)]
NILAI
## [1] 40
# Gambar 2.22
NILAI=c(100,95,70,80,25,60,80,60,55,90)
NILAI
##  [1] 100  95  70  80  25  60  80  60  55  90
NILAI[NILAI>80]
## [1] 100  95  90
# Gambar 2.24
NILAI=c(100,95,70,80,25,60,80,60,55,90)
NILAI
##  [1] 100  95  70  80  25  60  80  60  55  90
NILAI[NILAI<70]
## [1] 25 60 60 55
# Gambar 2.26
NILAI=c(100,95,70,80,25,60,80,60,55,90)
NILAI
##  [1] 100  95  70  80  25  60  80  60  55  90
NILAI[NILAI>60&NILAI<80]
## [1] 70
# Gambar 2.28
NILAI=c(100,95,70,80,25,60,80,60,55,90)
NILAI
##  [1] 100  95  70  80  25  60  80  60  55  90
NILAI[NILAI>80 | NILAI<30]
## [1] 100  95  25  90
# Gambar 2.30
NILAI=c(100,95,70,80,25,60,80,60,55,90)
NILAI
##  [1] 100  95  70  80  25  60  80  60  55  90
NILAI=NILAI[NILAI<75]
NILAI
## [1] 70 25 60 60 55
# Gambar 2.32
NILAI=c(100,95,70,80,25,60,80,60,55,90)
NILAI
##  [1] 100  95  70  80  25  60  80  60  55  90
NILAI=NILAI[NILAI>90]
NILAI
## [1] 100  95
# Gambar 2.34
fungsi=function(x)
{
  for(i in 1 : length(x))
  {
    if(x[i]<65)
    {
      x[i]=x[i]+10;
    }
    print(x[i])
  }
}
A=c(100,95,70,80,25,60,80,60,55,90)
fungsi(A)
## [1] 100
## [1] 95
## [1] 70
## [1] 80
## [1] 35
## [1] 70
## [1] 80
## [1] 70
## [1] 65
## [1] 90
# Gambar 2.36
mode(100)
## [1] "numeric"
simpan=c(1000)
mode(simpan)
## [1] "numeric"
# Gambar 2.38
mode("HALO")
## [1] "character"
simpan=c("HALO")
mode(simpan)
## [1] "character"
# Gambar 2.40
d=c(F)
d
## [1] FALSE
a=c(T)
a
## [1] TRUE
mode(d)
## [1] "logical"
mode(a)
## [1] "logical"
# Gambar 2.42
kuadrat=function(x)
{
  print(x*x);
}
A=c(4)
kuadrat(A)
## [1] 16
mode(kuadrat)
## [1] "function"
# Gambar 2.44
A=c(1,2,3)
B=c(4,5,6)
C=A+B
C
## [1] 5 7 9
A=c(1,2,3)
B=2+A
B
## [1] 3 4 5
A=c(2,4,6)
B=c(1,3,5)
B-A
## [1] -1 -1 -1
A=c(4,8,12)
A*0.5
## [1] 2 4 6
A=c(4,8,12)
B=c(2,2,2)
A/B
## [1] 2 4 6
A=c(3,6,1)
B=c(2,2,0)
A^B
## [1]  9 36  1
A=c(5,2,7)
B=c(3,2,6)
C=A%%B
C
## [1] 2 0 1
# Gambar 2.46
A=c(100,70,80,55,80,70,80)
length(A)
## [1] 7
# Gambar 2.48
A=c(70,80,50,25,100,60)
sort(A)
## [1]  25  50  60  70  80 100
# Gambar 2.50
A=c(100,50,70,80,60)
diff(A)
## [1] -50  20  10 -20
# Gambar 2.52
A=c(50,60,70,80)
sum(A)
## [1] 260
# Gambar 2.54
a=sqrt(81)
a
## [1] 9
b=sqrt(a)
b
## [1] 3
# Gambar 2.56
A=c(10,25,90,75,95,57)
max(A)
## [1] 95
min(A)
## [1] 10
# Gambar 2.58
exp(1)
## [1] 2.718282
exp(2)
## [1] 7.389056
# Gambar 2.60
pi
## [1] 3.141593
# Gambar 2.62
options(digits=3)
pi
## [1] 3.14
options(digits=10)
pi
## [1] 3.141592654
# Gambar 2.64
seq(from=1, to=10)
##  [1]  1  2  3  4  5  6  7  8  9 10
seq(from=2, by=0.5, length.out=4)
## [1] 2.0 2.5 3.0 3.5
# Gambar 2.66
panggil=function(x,y,z)
{
  a=x;
  print(a);
  for(i in x : z)
  {
    a=a+y;
    if(a>z)
    {
      break;
    }
    print(a);
  }
}
panggil(2,3,30)
## [1] 2
## [1] 5
## [1] 8
## [1] 11
## [1] 14
## [1] 17
## [1] 20
## [1] 23
## [1] 26
## [1] 29
# Gambar 2.68
seq(2,30,3)
##  [1]  2  5  8 11 14 17 20 23 26 29
# Gambar 2.70
A=c(10,10,30,10,30,10,10,40,40,70,90,70,80,60,60,90)
table(A)
## A
## 10 30 40 60 70 80 90 
##  5  2  2  2  2  1  2
A=c(10,10,30,10,30,10,10,40,40,70,90,70,80,60,60,90)
table(A)/length(A)
## A
##     10     30     40     60     70     80     90 
## 0.3125 0.1250 0.1250 0.1250 0.1250 0.0625 0.1250
hasil=c("ya","tidak","ya","ya","ya","ya","tidak","ya","tidak","ya")
table(hasil)
## hasil
## tidak    ya 
##     3     7
hasil=c("ya","tidak","ya","ya","ya","ya","tidak","ya","tidak","ya")
table(hasil)/length(hasil)
## hasil
## tidak    ya 
##   0.3   0.7
# Gambar 2.72
A=c("ikan","ikan","udang"," ikan","udang","ikan","ikan"," udang")
factor(A)
## [1] ikan   ikan   udang   ikan  udang  ikan   ikan    udang
## Levels:  ikan  udang ikan udang
A=c("sarjana","diploma","sarjana","pengangguran","sarjana","diploma","diploma","pengangguran")
factor(A)
## [1] sarjana      diploma      sarjana      pengangguran sarjana     
## [6] diploma      diploma      pengangguran
## Levels: diploma pengangguran sarjana
# Gambar 2.74
A=c(10,10,10,10,20,20,30,30,30,30,30,30)
barplot(table(A))

# Gambar 2.75
A=c(10,10,10,10,20,20,30,30,30,30,30,30)

# Gambar 2.76
A=c(10, 10, 10, 10, 20, 20, 30, 30, 30, 30, 30, 30)
barplot(table(A))
barplot(table(A)/length(A))

barplot(table(A)/length(A))

# Gambar 2.77
A=c(10,10,10,10,10,20,20,20,30,30,40)
table(A)
## A
## 10 20 30 40 
##  5  3  2  1
barplot(table(A))

# Gambar 2.78
barplot(table(A)/length(A))

# Gambar 2.79
A=c(10,10,10,10,10,20,20,20,30,30,40)
table(A)
## A
## 10 20 30 40 
##  5  3  2  1
nilai=c(10,20,30,40)
frekuensi=c(5,3,2,1)
plot(nilai,frekuensi)

A=c(10,10,10,10,10,20,20,20,30,30,40)
plot(table(A))

# Gambar 2.80
A=c(10,10,10,10,10,20,20,20,30,30,40)
table(A)
## A
## 10 20 30 40 
##  5  3  2  1
nilai=c(10,20,30,40)
frekuensi=c(5,3,2,1)
plot(nilai,frekuensi)

# Gambar 2.81
nilai=c(10,20,30,40)
frekuensi=c(5,3,2,1)
plot(nilai,frekuensi)

# Gambar 2.82
A=c(10,10,10,10,10,20,20,20,30,30,40)
plot(table(A))