Slide 1

Slide 1 text

@kilometer Beginner’s Session 2 -- data manipulation --

Slide 2

Slide 2 text

Who @kilometer Postdoc (Ph.D engineering) Behavioral System Neuro Imaging Medical System Engineering R ~ 10 years? : Kyoto

Slide 3

Slide 3 text

’ Basic Technics to be Freedom in R Beginner to Intermediate level

Slide 4

Slide 4 text

Think Write Run Read

Slide 5

Slide 5 text

Run!!! https://www.amazon.co.jp/dp/B00Y0UI990/

Slide 6

Slide 6 text

Think Write Read Freely Stress-fee

Slide 7

Slide 7 text

Language Thought

Slide 8

Slide 8 text

George Boole 1815 - 1864 A Class-Room Introduction to Logic https://niyamaklogic.wordpress.co m/category/laws-of-thoughts/ Mathematician Philosopher &

Slide 9

Slide 9 text

Boolean Algebra George Boole 1815 - 1864 # equal to # not equal to # or # and # is A in B? wikipedia

Slide 10

Slide 10 text

# is A in B? Boolean Algebra # is A in B?

Slide 11

Slide 11 text

Think Write Read Freely Stress-fee

Slide 12

Slide 12 text

Basic Technics to be Freedom in R Pipe algebra Verb functions data.frame

Slide 13

Slide 13 text

Basic Technics to be Freedom in R data.frame What is? Access Handling

Slide 14

Slide 14 text

What is “data.frame” data.frame is a “list” looks like a “matrix” list: a set of “vector”(s) vector: 1 dimensional object

Slide 15

Slide 15 text

vector in Excel

Slide 16

Slide 16 text

vector in R in Excel

Slide 17

Slide 17 text

vector

Slide 18

Slide 18 text

vector

Slide 19

Slide 19 text

vector seq{base} Sequence Generation Description Generate regular sequences. seq is a standard generic with a default method. … Usage seq(...) ## Default S3 method: seq(from = 1, to = 1, by = ((to - from)/(length.out - 1)), length.out = NULL, along.with = NULL, ...)

Slide 20

Slide 20 text

vector

Slide 21

Slide 21 text

vector

Slide 22

Slide 22 text

What is “data.frame” data.frame is a “list” looks like a “matrix” list: a set of “vector”(s) vector: a one direction object ☑

Slide 23

Slide 23 text

list

Slide 24

Slide 24 text

list

Slide 25

Slide 25 text

list

Slide 26

Slide 26 text

list

Slide 27

Slide 27 text

What is “data.frame” data.frame is a “list” looks like a “matrix” list: a set of “vector”(s) vector: 1 dimentional object ☑ ☑

Slide 28

Slide 28 text

data.frame in R in Excel

Slide 29

Slide 29 text

data.frame > df1 id value 1 a 11 2 b 12 3 c 13 4 d 14 5 e 15 > df1$value[2:3] [1] 12 13 > df1[5, 2] [1] 15 row column

Slide 30

Slide 30 text

data.frame > df1 id value 1 a 11 2 b 12 3 c 13 4 d 14 5 e 15 > df1$value[2:3] [1] 12 13 > df1[5, 2] [1] 15 row column column row

Slide 31

Slide 31 text

data.frame > summary(df1) id value a:1 Min. :11 b:1 1st Qu.:12 c:1 Median :13 d:1 Mean :13 e:1 3rd Qu.:14 Max. :15

Slide 32

Slide 32 text

data.frame > str(df1) 'data.frame': 5 obs. of 2 variables: $ id : Factor w/ 5 levels "a","b","c","d",… $ data: int 11 12 13 14 15

Slide 33

Slide 33 text

data.frame > str(df1) 'data.frame': 5 obs. of 2 variables: $ id : Factor w/ 5 levels "a","b","c","d",… $ value: int 11 12 13 14 15 row column

Slide 34

Slide 34 text

data.frame $ > str(iris) row column $ " " $ ' ' ' ' "$ "

Slide 35

Slide 35 text

data.frame > head(iris)

Slide 36

Slide 36 text

data.frame > plot(iris)

Slide 37

Slide 37 text

Boolean Algebra George Boole 1815 - 1864 # equal to # not equal to # or # and # is A in B? wikipedia

Slide 38

Slide 38 text

data.frame $ ' row column row column > str(iris1) ' $ ' $ ' ' ' row column Boolean

Slide 39

Slide 39 text

$ ( data.frame ) $ ( ( ( $ ( $ $ $ ( ) ( ) ( ) $ $ $ $ $ $ ) ) )

Slide 40

Slide 40 text

in Excel Basic Technics to be Freedom in R in R

Slide 41

Slide 41 text

Slide 42

Slide 42 text

more

Slide 43

Slide 43 text

Basic Technics to be Freedom in R Pipe algebra data.frame

Slide 44

Slide 44 text

1JQFBMHFCSB {magrittr} dplyr yutanihilation https://speakerdeck.com/yutannihilation/dplyrzai-ru-men-ji-ben-bian

Slide 45

Slide 45 text

{magrittr} 8@("* 6 ("* /=?.; 4 13 A("*B$)& -9 5:<1 R#+,'%!072>https://rlangradio.org/ 1JQFBMHFCSB

Slide 46

Slide 46 text

{magrittr} # # 1JQFBMHFCSB

Slide 47

Slide 47 text

{magrittr} # *OQVU 0VUQVU ① ② ③ 5IJOLJOHGMPX 4USVDUVSF 1JQFBMHFCSB

Slide 48

Slide 48 text

{magrittr} # *OQVU 0VUQVU 5IJOLJOHGMPX 3FBEJOHqPX 1JQFBMHFCSB

Slide 49

Slide 49 text

{magrittr} # */ 065 5IJOLJOH 4USVDUVSF 1JQFBMHFCSB

Slide 50

Slide 50 text

{magrittr} # */ 065 5IJOLJOH 3FBEJOH 1JQFBMHFCSB

Slide 51

Slide 51 text

{magrittr} # 1JQFBMHFCSB

Slide 52

Slide 52 text

{magrittr} # */ 065 ① ② ③ */ 065 */ 065 5IJOLJOH 3FBEJOH 1JQFBMHFCSB

Slide 53

Slide 53 text

{magrittr} # 536&*/ 5FNQPSBM065 ① ② ③ 5FNQ*/ 5FNQ065 5FNQ065 536&065 5IJOLJOH 3FBEJOH 1JQFBMHFCSB

Slide 54

Slide 54 text

{magrittr} # 536&*/ 536&065 5IJOLJOH 3FBEJOH 1JQFBMHFCSB

Slide 55

Slide 55 text

{magrittr} # */ 065 1JQFBMHFCSB

Slide 56

Slide 56 text

{magrittr} # */ 065 1JQFBMHFCSB

Slide 57

Slide 57 text

{magrittr} # */ 065 EPU 1JQFBMHFCSB

Slide 58

Slide 58 text

{magrittr} ͜Ε 1JQFBMHFCSB

Slide 59

Slide 59 text

{magrittr} “Passive” writing “Active” writing B AF A FB 1JQFBMHFCSB

Slide 60

Slide 60 text

{magrittr} " ( (. $ (" ( "(") ) ( ( $ ) , (" ) ' % % $ ' " % $ % % $ " % $ ' " ) ( , ) ) ) ) ( "(") 1JQFBMHFCSB

Slide 61

Slide 61 text

{magrittr} %$ 0 " $,, $ $ $' , , ( ( . $ % ) % '", ' ) % $ , ' , % '", ' , % $ , ' ) $ ,( / % . % ,( $', 1JQFBMHFCSB

Slide 62

Slide 62 text

{magrittr} * 0"06 ,"(0*220 *0*1 0$., 120 *12 . 1% 4 -3, 0.2"2*.- -3, "220 %*,-", 1 *12 . $)0 " -(2) " *%2) $)0 $ -2 0 ", % -3, "220 -", 1 $)0 " -(2) 1$" .(* 5 -3, 1JQFBMHFCSB

Slide 63

Slide 63 text

{magrittr} tee algebra chaindichika http://d.hatena.ne.jp/dichika/20140731/p1 1JQFBMHFCSB

Slide 64

Slide 64 text

Think Write Read Freely Stress-fee Sequential =

Slide 65

Slide 65 text

http://maker.usoko.net/nounai/

Slide 66

Slide 66 text

http://maker.usoko.net/nounai/ more

Slide 67

Slide 67 text

Basic Technics to be Freedom in R Pipe algebra Verb functions data.frame

Slide 68

Slide 68 text

# add column # select column # select row # arrange row # summary of values # fusion two dfs {dplyr} WFSCT WFSCGVODUJPOT

Slide 69

Slide 69 text

It (dplyr) provides simple “verbs” to help you translate your thoughts into code. functions that correspond to the most common data manipulation tasks Introduction to dplyr https://cran.r-project.org/web/packages/dplyr/vignettes/dplyr.html WFSCT {dplyr}

Slide 70

Slide 70 text

dplyr - ,/ #0'" (!$* %. 1) (+) Introduction to dplyr https://cran.r-project.org/web/packages/dplyr/vignettes/dplyr.html WFSCT {dplyr} &/

Slide 71

Slide 71 text

WFSCT S V O C M (, , etc)

Slide 72

Slide 72 text

WFSCT S V O C M {dplyr}verb

Slide 73

Slide 73 text

Think Write Read Freely Seamless Sequential

Slide 74

Slide 74 text

# add column # select column # select row # arrange row # summary of values # fusion two dfs {dplyr} WFSCT WFSCGVODUJPOT

Slide 75

Slide 75 text

WFSCT {dplyr} ΧϥϜͷ௥Ճ +

Slide 76

Slide 76 text

%$ 0 )%0 $ $ , , ' (/ , , ( ( . $ % ) % '", ' ) % $ , ' , % '", ' , % $ , ' ) $ ,( / % . % ,( $', WFSCT {dplyr}

Slide 77

Slide 77 text

%$ * *0 )%0* $*$ , , '*(/ *( ' , * ( ( . *$ % ) % ' , ' ) % $ , ' , % ' , ' , % $ , ' ) $ ,(* / % . % 1 ,( 2 ' WFSCT {dplyr} over write

Slide 78

Slide 78 text

WFSCT {dplyr} #

Slide 79

Slide 79 text

$ $) )$ $ % % $ % ( $ % ' ' WFSCT {dplyr}

Slide 80

Slide 80 text

“ ” % $ $ WFSCT {dplyr} Select help functions

Slide 81

Slide 81 text

WFSCT {dplyr} # Select help functions https://kazutan.github.io/blog/2017/04/dplyr-select-memo/ dplyr::selectkazutan

Slide 82

Slide 82 text

# # # # # # {dplyr} WFSCT WFSCؔ਺܈

Slide 83

Slide 83 text

WFSCT {dplyr} #

Slide 84

Slide 84 text

WFSCT {dplyr} 'data.frame': 50 obs. of 5 variables: $ Sepal.Length: num 7 6.4 6.9 5.5 6.5 5.7 6.3 ... $ Sepal.Width : num 3.2 3.2 3.1 2.3 2.8 2.8 ... $ Petal.Length: num 4.7 4.5 4.9 4 4.6 4.5 4.7 ... $ Petal.Width : num 1.4 1.5 1.5 1.3 1.5 1.3 ... $ Species : Factor w/ 3 levels "setosa","versicolor",..: 2 2 2 2 2 2 2 2 2 2 ...

Slide 85

Slide 85 text

WFSCT {dplyr} NSE (Non-Standard Evaluation) 'data.frame': 50 obs. of 5 variables: $ Sepal.Length: num 7 6.4 6.9 5.5 6.5 5.7 6.3 ... $ Sepal.Width : num 3.2 3.2 3.1 2.3 2.8 2.8 ... $ Petal.Length: num 4.7 4.5 4.9 4 4.6 4.5 4.7 ... $ Petal.Width : num 1.4 1.5 1.5 1.3 1.5 1.3 ... $ Species : Factor w/ 3 levels "setosa","versicolor",..: 2 2 2 2 2 2 2 2 2 2 ...

Slide 86

Slide 86 text

/4&ͷ࿩ NSE (Non-Standard Evaluation) SE (Standard Evaluation) http://dplyr.tidyverse.org/articles/programming.html Programming with dplyr

Slide 87

Slide 87 text

/4&ͷ࿩ NSE df SQL http://dplyr.tidyverse.org/articles/programming.html Programming with dplyr

Slide 88

Slide 88 text

/4&ͷ࿩ NSE http://dplyr.tidyverse.org/articles/programming.html Programming with dplyr $ " (!&) ( # %)+* # verb (' ) # noun (' )

Slide 89

Slide 89 text

/4&ͷ࿩ Because of NSE.. http://dplyr.tidyverse.org/articles/programming.html Programming with dplyr This do NOT work There is No “my_var” column in df

Slide 90

Slide 90 text

/4&ͷ࿩ dplyrTidyval https://speakerdeck.com/yutannihilation/dplyrzai-ru-men-tidyevalbian dplyrTidyval yutanihilation

Slide 91

Slide 91 text

/4&ͷ࿩ % dplyr +,Tidyval)-!' https://speakerdeck.com/yutannihilation/dplyrzai-ru-men-tidyevalbian "*# . . *$&( dplyr +,Tidyval)-yutanihilation

Slide 92

Slide 92 text

# # # # # # {dplyr} WFSCT WFSCؔ਺܈

Slide 93

Slide 93 text

WFSCT {dplyr} #

Slide 94

Slide 94 text

WFSCT {dplyr} #

Slide 95

Slide 95 text

WFSCT {dplyr} #

Slide 96

Slide 96 text

WFSCT {dplyr} #

Slide 97

Slide 97 text

WFSCT {dplyr} https://twitter.com/yutannihilation/status/551572539697143808 #

Slide 98

Slide 98 text

Basic Technics to be Freedom in R Pipe algebra Verb functions data.frame mutate, select, filter, arrange, summaries, join

Slide 99

Slide 99 text

(SBNNBSPGEBUBNBOJQVMBUJPO By constraining your options, it helps you think about your data manipulation challenges. Introduction to dplyr https://cran.r-project.org/web/packages/dplyr/vignettes/dplyr.html

Slide 100

Slide 100 text

("% ) $ * !'+ Introduction to dplyr https://cran.r-project.org/web/packages/dplyr/vignettes/dplyr.html !' (SBNNBSPGEBUBNBOJQVMBUJPO

Slide 101

Slide 101 text

И ́ горь Ф Страви́нский

Slide 102

Slide 102 text

https://www.tidyverse.org/

Slide 103

Slide 103 text

No content