# A tibble: 4 × 4
name assignment1 assignment2 quiz1
<chr> <chr> <chr> <chr>
1 Billy <NA> D C
2 Suzy F <NA> <NA>
3 Lionel B C B
4 Jenny A A B
Class 9
*apply familytidyverse# A tibble: 4 × 4
name assignment1 assignment2 quiz1
<chr> <chr> <chr> <chr>
1 Billy <NA> D C
2 Suzy F <NA> <NA>
3 Lionel B C B
4 Jenny A A B
Is this table tidy?
# A tibble: 12 × 3
name assessment grade
<chr> <chr> <chr>
1 Billy assignment1 <NA>
2 Billy assignment2 D
3 Billy quiz1 C
4 Suzy assignment1 F
5 Suzy assignment2 <NA>
6 Suzy quiz1 <NA>
7 Lionel assignment1 B
8 Lionel assignment2 C
9 Lionel quiz1 B
10 Jenny assignment1 A
11 Jenny assignment2 A
12 Jenny quiz1 B
How about this one?
# A tibble: 3 × 5
assessment Billy Suzy Lionel Jenny
<chr> <chr> <chr> <chr> <chr>
1 assignment1 <NA> F B A
2 assignment2 D <NA> C A
3 quiz1 C <NA> B B
# A tibble: 12 × 3
assessment student grade
<chr> <chr> <chr>
1 assignment1 Billy <NA>
2 assignment1 Suzy F
3 assignment1 Lionel B
4 assignment1 Jenny A
5 assignment2 Billy D
6 assignment2 Suzy <NA>
7 assignment2 Lionel C
8 assignment2 Jenny A
9 quiz1 Billy C
10 quiz1 Suzy <NA>
11 quiz1 Lionel B
12 quiz1 Jenny B
tidyverseA collection of packages to create, process and manipulate tidy data.
dplyr, provides functions for data manipulationtidyr, provide functions to get to tidy dataggplot2, a system to create figures.stringr, provides functions to deal with stringsVisit tidyverse web together.
dplyr vs base Rfilter (by condition) and slice (by index) to subset rowsselect to subset columnspull to read a column as a vector (like the double bracket [[]])mutate to add a new column# A tibble: 12 × 3
assessment student grade
<chr> <chr> <chr>
1 assignment1 Billy <NA>
2 assignment1 Suzy F
3 assignment1 Lionel B
4 assignment1 Jenny A
5 assignment2 Billy D
6 assignment2 Suzy <NA>
7 assignment2 Lionel C
8 assignment2 Jenny A
9 quiz1 Billy C
10 quiz1 Suzy <NA>
11 quiz1 Lionel B
12 quiz1 Jenny B
# A tibble: 2 × 3
assessment student grade
<chr> <chr> <chr>
1 assignment1 Jenny A
2 assignment2 Jenny A
# A tibble: 2 × 3
assessment student grade
<chr> <chr> <chr>
1 assignment1 Billy <NA>
2 assignment1 Suzy F
# A tibble: 12 × 2
student grade
<chr> <chr>
1 Billy <NA>
2 Suzy F
3 Lionel B
4 Jenny A
5 Billy D
6 Suzy <NA>
7 Lionel C
8 Jenny A
9 Billy C
10 Suzy <NA>
11 Lionel B
12 Jenny B
[1] "Billy" "Suzy" "Lionel" "Jenny" "Billy" "Suzy" "Lionel" "Jenny"
[9] "Billy" "Suzy" "Lionel" "Jenny"
# A tibble: 12 × 4
assessment student grade good
<chr> <chr> <chr> <dbl>
1 assignment1 Billy <NA> NA
2 assignment1 Suzy F 0
3 assignment1 Lionel B 0
4 assignment1 Jenny A 1
5 assignment2 Billy D 0
6 assignment2 Suzy <NA> NA
7 assignment2 Lionel C 0
8 assignment2 Jenny A 1
9 quiz1 Billy C 0
10 quiz1 Suzy <NA> NA
11 quiz1 Lionel B 0
12 quiz1 Jenny B 0
Use dplyr syntax to redo this task. Share your solution in Chat.
%>%.. to refer to the result from the previous step. By default, the result is passed as the first argument.
Revisit task 2 in code cracker:
Your task:
dplyr pipelinedplyr syntax one by one.read.csv to read csv filewrite.csv to save csv fileInteractive environment (e.g. console):
getwd() to get the working directorysetwd() to set the new working directoryR markdown knit directory:
R script
Package here will definitely what you should try.
Function here of package here will specify the right path of a file within a project:
here::here() will give you the project root pathhere::here("/a/path/relative/to/your/project/root") to specify the right path of a file within your package.dplyr if you did not complete them earlier in class.