Danny Kaplan
CVC June 21, 2016
Your commands will be written as chains.
Links are connected by the chaining symbol %>%
This is done with the assignment operator, <-
Name_of_result <-
Starting_data_frame %>%
first verb (arguments for details) %>%
next verb (and its arguments) %>%
... and so on, up through ...
last verb (and its arguments)
Princes <-
BabyNames %>%
filter(grepl("Prince", name)) %>%
group_by(year) %>%
summarise(total = sum(count))
%>%
is at the end of each line.
Princes <-
is assignment%>%
.There are two distinct aspects involved in reading or writing a command chain.
The focus today is on syntax.
From the dictionarty
part of speech noun
parts of speech a category to which a word is assigned in accordance with its syntactic functions. In English the main parts of speech are noun, pronoun, adjective, determiner, verb, adverb, preposition, conjunction, and interjection.
RegisteredVoters
.(
and, eventually, a closing )
.The things that go inside a function’s parentheses are called arguments.
Many functions take named arguments which look like a name followed by an =
sign, e.g.
summarise(total = sum(count))
You can also consider the data frame passed along by %>%
as an argument to the following function.
Variables are the components of data frames.
(
.Constants are single values, most commonly a number or a character string.
"like this."
-42
1984
3.14159
Consider this command chain:
Princes <-
BabyNames %>%
filter(grepl("Prince", name)) %>%
group_by(year) %>%
summarise(total = sum(count))
Just from the syntax, you should be able to tell which of the five different kinds of object each of these things is: Princes
, BabyNames
, filter
, grepl
, "Prince"
, name
, group_by
, year
, summarise
, total
, sum
, count
.
Explain your reasoning.