Pengantar Penulisan Fungsi di R
Richie Cotton
Data Evangelist at DataCamp
my_fun <- function(arg1, arg2) {
# Do something
}
Tanda tangan
function(arg1, arg2)
Body
{
# Do something
}
library(readr)
test_scores_geography_raw <- read_csv("test_scores_geography.csv")
library(dplyr)
library(lubridate)
test_scores_geography_clean <- test_scores_geography_raw %>%
select(person_id, first_name, last_name, test_date, score) %>%
mutate(test_date = mdy(test_date)) %>%
filter(!is.na(score))
library(readr)
test_scores_english_raw <- read_csv("test_scores_english.csv")
library(dplyr)
library(lubridate)
test_scores_english_clean <- test_scores_english_raw %>%
select(person_id, first_name, last_name, test_date, score) %>%
mutate(test_date = mdy(test_date)) %>%
filter(!is.na(score))
library(readr)
test_scores_art_raw <- read_csv("test_scores_art.csv")
library(dplyr)
library(lubridate)
test_scores_art_clean <- test_scores_art_raw %>%
select(person_id, first_name, last_name, test_date, score) %>%
mutate(test_date = mdy(test_date)) %>%
filter(is.na(score))
library(readr)
test_scores_spanish_raw <- read_csv("test_scores_spanish.csv")
library(dplyr)
library(lubridate)
test_scores_spanish_clean <- test_scores_spanish_raw %>%
select(person_id, first_name, last_name, test_date, score) %>%
mutate(test_date = mdy(test_date)) %>%
filter(!is.na(score))
import_test_scores <- function() {
}
import_test_scores <- function() {
test_scores_geography_raw <- read_csv("test_scores_geography.csv")
test_scores_geography_clean <- test_scores_geography_raw %>%
select(person_id, first_name, last_name, test_date, score) %>%
mutate(test_date = mdy(test_date)) %>%
filter(!is.na(score))
}
import_test_scores <- function(filename) { # <- hanya 1 argumen
test_scores_geography_raw <- read_csv("test_scores_geography.csv")
test_scores_geography_clean <- test_scores_geography_raw %>%
select(person_id, first_name, last_name, test_date, score) %>%
mutate(test_date = mdy(test_date)) %>%
filter(!is.na(score))
}
import_test_scores <- function(filename) {
test_scores_geography_raw <- read_csv(filename) # <- ganti nama file spesifik
test_scores_geography_clean <- raw_data %>%
select(person_id, first_name, last_name, test_date, score) %>%
mutate(test_date = mdy(test_date)) %>%
filter(!is.na(score))
}
import_test_scores <- function(filename) {
test_scores_raw <- read_csv(filename) # <- nama variabel digeneralisasi
test_scores_clean <- test_scores_raw %>% # <- nama variabel digeneralisasi
select(person_id, first_name, last_name, test_date, score) %>%
mutate(test_date = mdy(test_date)) %>%
filter(!is.na(score))
}
import_test_scores <- function(filename) {
test_scores_raw <- read_csv(filename)
test_scores_raw %>% # <- hapus assignment akhir
select(person_id, first_name, last_name, test_date, score) %>%
mutate(test_date = mdy(test_date)) %>%
filter(!is.na(score))
}
test_scores_geography <- import_test_scores("test_scores_geography.csv")
test_scores_english <- import_test_scores("test_scores_english.csv")
test_scores_art <- import_test_scores("test_scores_art.csv")
test_scores_spanish <- import_test_scores("test_scores_spanish.csv")
x: Vektor nilai untuk diambil sampelnya.size: Berapa kali ingin mengambil sampel dari x?replace: Ambil sampel dengan pengembalian atau tidak?prob: Vektor bobot untuk tiap nilai x, totalnya satu.Pengantar Penulisan Fungsi di R