# Make a vector
<- c("a", "b", "c", "d", "e")
my_vec
# Use bracket notation to retrieve one element
3] my_vec[
[1] "c"
After today’s session you will be able to:
install.packages
requires the package name be in quotes
library
requires requires unquoted names.install.packages
= buying a set of tools from the store and putting them in your home
library
= moving the tools that you already own to your workbench
palmerpenguins
package
library
function
?palmerpenguins
to see the package-level help file
package::function()
palmerpenguins
includes an example dataset on penguinspeng_df <- palmerpenguins::penguins
dplyr
package
dplyr
has a function called glimpse
that shows you core structures of data
glimpse
and run it on peng_df
class(class)
str(str)
letters
letters
to an object called my_vec
my_vec
using the length
function
my_vec
using bracket notation
my_vec
c
)!
TRUE
or FALSE
==
operator
|
operator
\
on keyboard
&
operator
==
operator
|
operator
\
on keyboardsubset
function with the peng_df
object
?subset
)
peng_df
to only Adelie penguins (and assign to a sub_v1
object)
species == "Adelie"
peng_df
to Adelie or Gentoo penguins
sub_v2
object
peng_df
to only male Gentoo penguins
sub_v3
object
==
, |
, or &
>
and <
>=
and <=
peng_df
to only penguins with a bill length greater than 40 mm
sub_v7
peng_df
to only penguins with a body mass less than or equal to 4,000 g
sub_v8
x == 1 | x == 2 | x == 3 | x == 4 …
%in%
operator to simplify this!
%in%
is effectively “if any of <this vector> matches the value”
x %in% c(1, 2, 3, 4, …)
!=
for “not equal to”
x != 10
%in%
to exclude a set of options
!x %in% c(...)
peng_df
is species is any of “Adelie”, “Gentoo”, or “Chinstrap”
%in%
operator
peng_df
to all islands except “Dream”