# Keep only 2 columns
select(porgs, id, age)
# Drop the mass column
select(porgs, -mass)
# Put the age column first, but
# keep everything else the same
select(porgs, age, everything())
# Sort by age w/ YOUNGEST on top
arrange(porgs, age)
# Sort by age w/ ELDEST on top
arrange(porgs, desc(age))
# Sort by colors and then by age
arrange(porgs, color, desc(age))
Function | Order of Input | Output |
---|---|---|
mdy() |
Month-Day-Year :: 05-18-2019 |
2019-05-18 |
mdy_hm() |
Month-Day-Year Hour:Minutes ::
05-18-2019 8:35 |
2019-05-18 08:35:00 UTC |
mdy_hms() |
Month-Day-Year Hour:Mins:Secs ::
05-18-2019 8:35:22 |
2019-05-18 08:35:22 UTC |
Function | Date element |
---|---|
year() |
Year |
month() |
Month as 1,2,3 |
day() |
Day of the month |
wday() |
Day of the week |
hour() |
Hour of the day (24hr) |
tz() |
Time zone |
left_join()
keeps all rows and columns in the left table,
and joins rows in the right table with matching IDs.
# Table w/ porg ages and heights
porgs
# Table w/ porg names
porg_names
# Join together by id columns
together <- left_join(porgs,
porg_names,
by = "id")
library(readr)
# Save data to a CSV text file
write_csv(porgs, "my_porg_data.csv")
library(ggsave)
# Save the last plot you made
ggsave("most_recent_plot.png")
# Save earlier plot stored to variable
best_plot <- ggplot()
ggsave(best_plot, "best_plot.png")
r
or rstats
+
"question"
[r]
tagHelp > Cheatsheets
?
in the Console# Function help
?read_csv
# Search help
help.search("boxplot")
#rstats
on CTRL
+ENTER
CTRL
+S
highlight
+CTRL
+Shift
+A
Use ifelse()
to create new values that depend on the value
of another column. For example, to only label the porgs with a height
over 60 cm as “tall”.
# When a porg's height is > 60 cm label it as "tall",
# otherwise label it as "short"
mutate(porgs, label = ifelse(height > 60, "tall", "short"))
Barbara.Monaco
Kristie.Ellickson
Dorian.Kvale
Carl.Stenoien
Andrea.Borich
Derek.Nagel