R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

PENGERTIAN LOOPING

APA itu Looping?

Looping adalah proses perulangan suatu data dengan tujuan membuat data berkelanjutan dengan syarat tertentu untuk menghentikan program.

Housing = read.csv("http://www.mosaic-web.org/go/datasets/Income-Housing.csv")

A. For Loop

For loop terdiri dari dua bagian yakni Header yang berisi kumpulan data, dan yang kedua body yang berisi blok kode yang akan dieksekusi perobjek berikut langkah-langkah membuat program looping dengan bahasa R:

1.Menentukan objek data yang ingin kita gunakan dalam loop,contoh : x_for <- 0 2.tambahkan persyaratan untuk memulai dan menghentikan looping
for ( i in 1 : 12 ) { 3. x_for <- x_for + 1 ,menandakan bahwa setiap terjadi looping akan bertambah 1 4.keluarkan input dengan print()

library(mosaicCalc)
## Loading required package: mosaic
## Registered S3 method overwritten by 'mosaic':
##   method                           from   
##   fortify.SpatialPolygonsDataFrame ggplot2
## 
## The 'mosaic' package masks several functions from core packages in order to add 
## additional features.  The original behavior of these functions should not be affected by this.
## 
## Attaching package: 'mosaic'
## The following objects are masked from 'package:dplyr':
## 
##     count, do, tally
## The following object is masked from 'package:Matrix':
## 
##     mean
## The following object is masked from 'package:ggplot2':
## 
##     stat
## The following objects are masked from 'package:stats':
## 
##     binom.test, cor, cor.test, cov, fivenum, IQR, median, prop.test,
##     quantile, sd, t.test, var
## The following objects are masked from 'package:base':
## 
##     max, mean, min, prod, range, sample, sum
## Loading required package: mosaicCore
## 
## Attaching package: 'mosaicCore'
## The following objects are masked from 'package:dplyr':
## 
##     count, tally
## 
## Attaching package: 'mosaicCalc'
## The following object is masked from 'package:stats':
## 
##     D
x_for <-  0 
for ( i in  1 : 12 )  {           
 
  x_for <- x_for +  1          
  print ( x_for ) 
} 
## [1] 1
## [1] 2
## [1] 3
## [1] 4
## [1] 5
## [1] 6
## [1] 7
## [1] 8
## [1] 9
## [1] 10
## [1] 11
## [1] 12

B.While Loop

x_while <-  0 
while ( x_while <  7 )  {         
  x_while <- x_while +  1       
  print ( x_while ) 
} 
## [1] 1
## [1] 2
## [1] 3
## [1] 4
## [1] 5
## [1] 6
## [1] 7

C.Repeat Loop

Repeat loop menggunakan break untuk menandakan kondisi perulangan sudah terpenuhi

x_repeat <-  0  
repeat {                       
 
  x_repeat <- x_repeat +  1    
  print  ( x_repeat )
 
  if ( x_repeat >=  10 )  {        
 
    break 
  } 
}
## [1] 1
## [1] 2
## [1] 3
## [1] 4
## [1] 5
## [1] 6
## [1] 7
## [1] 8
## [1] 9
## [1] 10