Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SP21 AEDE6120
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Angie Liu
SP21 AEDE6120
Commits
c923fb18
Commit
c923fb18
authored
4 years ago
by
Angie Liu
Browse files
Options
Downloads
Patches
Plain Diff
Delete lab_2.R
parent
13b04c37
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lab_2.R
+0
-60
0 additions, 60 deletions
lab_2.R
with
0 additions
and
60 deletions
lab_2.R
deleted
100644 → 0
+
0
−
60
View file @
13b04c37
# Lab 2
# tidyverse
# install packages
install.packages
(
"tidyverse"
)
# load packages
library
(
tidyverse
)
require
(
tidyverse
)
# the pipe operator -- %>%
?
mtcars
mtcars
sqrt
(
mean
(
colSums
(
mtcars
)))
mtcars
%>%
colSums
%>%
mean
%>%
sqrt
# x %>% f() f(x)
# x %>% f %>% g g(f(x))
# select columns -- select()
mtcars
%>%
select
(
mpg
,
cyl
,
hp
)
mtcars
%>%
select
(
-
am
,
-
vs
)
# select rows -- filter()
mtcars
%>%
filter
(
cyl
==
8
)
mtcars
%>%
filter
(
cyl
==
8
&
gear
>=
5
)
# create columns -- mutate()
mtcars
%>%
mutate
(
four_cyl
=
(
cyl
==
4
),
twice_hp
=
2
*
hp
)
# sort -- arrange()
mtcars
%>%
arrange
(
vs
)
mtcars
%>%
arrange
(
vs
,
desc
(
gear
))
# exercise
mtcars
%>%
select
(
-
qsec
)
%>%
filter
(
carb
>
2
)
%>%
mutate
(
twice_mpg
=
2
*
mpg
)
%>%
arrange
(
hp
,
disp
,
desc
(
vs
))
# present basic statistics -- summarize()
# by group -- group_by()
mtcars
%>%
summarise
(
mean
(
hp
),
sum
(
mpg
),
min
(
gear
),
median
(
carb
),
count
=
n
())
mtcars
%>%
group_by
(
vs
)
%>%
summarise
(
mean
(
hp
),
n
())
?
group_by
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment