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.

Latihan 1 – Vektor dengan elemen campuran

nama_vector <- c(5, FALSE, “true”, “8.3”, “Statistika”) nama_vector

Penjelasan: Vektor di R harus homogen. Karena ada campuran tipe data, R melakukan coercion otomatis menjadi character.

Latihan 2 – List dengan elemen yang sama

contoh_list <- list(5, FALSE, “true”, “8.3”, “Statistika”) contoh_list

Penjelasan: List mempertahankan tipe data asli setiap elemen, sedangkan vector melakukan coercion. List lebih fleksibel.

Latihan 3 – Data frame kelompok KKN

kelompok_kkn <- data.frame( nama = c(“Andi”, “Budi”, “Citra”, “Dewi”, “Eka”, “Fajar”, “Gita”, “Hadi”, “Intan”, “Joko”), nim = c(“2401001”, “2401002”, “2401003”, “2401004”, “2401005”, “2401006”, “2401007”, “2401008”, “2401009”, “2401010”), prodi = c(“Statistika”, “Matematika”, “Statistika”, “Biologi”, “Fisika”, “Statistika”, “Kimia”, “Statistika”, “Informatika”, “Statistika”) ) kelompok_kkn kelompok_kkn[3, ] kelompok_kkn$nama kelompok_kkn[7, “nama”] kelompok_kkn[4:6, c(“nim”, “prodi”)]

Penjelasan pemanggilan:

$ → ambil kolom (paling mudah)

[baris, ] → ambil baris

[baris, kolom] → ambil elemen/subset (paling fleksibel)

Latihan 4 – Data frame dengan missing value (NA)

df_na <- data.frame( nama = c(“Andi”, “Budi”, NA, “Dewi”, “Eka”, “Fajar”, NA), nilai = c(85, NA, 92, 78, NA, 88, 95), prodi = c(“Statistika”, “Matematika”, “Statistika”, NA, “Fisika”, “Statistika”, “Biologi”) ) df_na is.na(df_na) which(is.na(df_na), arr.ind = TRUE)