R 函数编写入门
Richie Cotton
Data Evangelist at DataCamp
mean 有 3 个参数
x:数值或日期时间向量。trim:在计算前从两端各移除的比例。na.rm:在计算前移除缺失值。按位置传参
mean(numbers, 0.1, TRUE)
按名称传参
mean(na.rm = TRUE, trim = 0.1, x = numbers)
常用参数用位置,少用参数用名称
mean(numbers, trim = 0.1, na.rm = TRUE)
library(readr)
test_scores_geography_raw <- read_csv("test_scores_geography.csv")
library(dplyr)
test_scores_geography_clean <- test_scores_geography_raw %>%
select(person_id, first_name, last_name, test_date, score)
library(readr)
test_scores_geography_raw <- read_csv("test_scores_geography.csv")
library(dplyr)
test_scores_geography_clean <- test_scores_geography_raw %>%
select(person_id, first_name, last_name, test_date, score)
library(readr)
test_scores_geography_raw <- read_csv("test_scores_geography.csv")
library(dplyr)
test_scores_geography_clean <- test_scores_geography_raw %>%
select(person_id, first_name, last_name, test_date, score)
library(readr)
test_scores_geography_raw <- read_csv("test_scores_geography.csv")
library(dplyr)
test_scores_geography_clean <- test_scores_geography_raw %>%
select(person_id, first_name, last_name, test_date, score)
library(readr)
test_scores_geography_raw <- read_csv("test_scores_geography.csv")
library(dplyr)
test_scores_geography_clean <- test_scores_geography_raw %>%
select(person_id, first_name, last_name, test_date, score)
library(readr)
test_scores_geography_raw <- read_csv("test_scores_geography.csv")
library(dplyr)
test_scores_geography_clean <- test_scores_geography_raw %>%
select(person_id, first_name, last_name, test_date, score)
library(readr)
test_scores_english_raw <- read_csv("test_scores_english.csv")
library(dplyr)
test_scores_english_clean <- test_scores_english_raw %>%
select(person_id, first_name, last_name, test_date, score)
library(readr)
test_scores_art_raw <- read_csv("test_scores_art.csv")
library(dplyr)
test_scores_art_clean <- test_scores_art_raw %>%
select(person_id, first_name, last_name, test_date, score)
library(readr)
test_scores_spanish_raw <- read_csv("test_scores_spanish.csv")
library(dplyr)
test_scores_spanish_clean <- test_scores_spanish_raw %>%
select(person_id, first_name, last_name, test_date, score)
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))
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))
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))
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))
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))
函数能消除重复代码,可
函数也便于复用与共享。
R 函数编写入门