Data Relations id score id sex age 2 10 1 m 19 3 18 2 m - - PowerPoint PPT Presentation

data relations
SMART_READER_LITE
LIVE PREVIEW

Data Relations id score id sex age 2 10 1 m 19 3 18 2 m - - PowerPoint PPT Presentation

Data Relations id score id sex age 2 10 1 m 19 3 18 2 m 22 4 21 3 NA NA 4 23 4 f 19 5 9 5 f 18 5 11 6 11 6 12 7 3 *_join(x, y) x y *_join(subject, exp, id) id score id sex age 2 10 1 m 19 3 18


slide-1
SLIDE 1

id sex age 1 m 19 2 m 22 3 NA NA 4 f 19 5 f 18 id score 2 10 3 18 4 21 4 23 5 9 5 11 6 11 6 12 7 3

Data Relations

slide-2
SLIDE 2

x y

*_join(x, y)

slide-3
SLIDE 3

id sex age 1 m 19 2 m 22 3 NA NA 4 f 19 5 f 18 id score 2 10 3 18 4 21 4 23 5 9 5 11 6 11 6 12 7 3

*_join(subject, exp, “id”)

slide-4
SLIDE 4

x y left_join(x, y)

slide-5
SLIDE 5

left_join(subject, exp)

id sex age 1 m 19 2 m 22 3 NA NA 4 f 19 5 f 18 id score 2 10 3 18 4 21 4 23 5 9 5 11 6 11 6 12 7 3 id sex age score 1 m 19 NA 2 m 22 10 3 NA NA 18 4 f 19 21 4 f 19 23 5 f 18 9 5 f 18 11

slide-6
SLIDE 6

x y left_join(y, x)

slide-7
SLIDE 7

left_join(exp, subject)

id sex age 1 m 19 2 m 22 3 NA NA 4 f 19 5 f 18 id score 2 10 3 18 4 21 4 23 5 9 5 11 6 11 6 12 7 3 id score sex age 2 10 m 22 3 18 NA NA 4 21 f 19 4 23 f 19 5 9 f 18 5 11 f 18 6 11 NA NA 6 12 NA NA 7 3 NA NA

slide-8
SLIDE 8

x y right_join(x, y)

slide-9
SLIDE 9

right_join(x, y)

id sex age 1 m 19 2 m 22 3 NA NA 4 f 19 5 f 18 id score 2 10 3 18 4 21 4 23 5 9 5 11 6 11 6 12 7 3 id sex age score 2 m 22 10 3 NA NA 18 4 f 19 21 4 f 19 23 5 f 18 9 5 f 18 11 6 NA NA 11 6 NA NA 12 7 NA NA 3

slide-10
SLIDE 10

x y inner_join(x, y)

slide-11
SLIDE 11

id sex age 1 m 19 2 m 22 3 NA NA 4 f 19 5 f 18 id score 2 10 3 18 4 21 4 23 5 9 5 11 6 11 6 12 7 3

inner_join(subject, exp)

id sex age score 2 m 22 10 3 NA NA 18 4 f 19 21 4 f 19 23 5 f 18 9 5 f 18 11

slide-12
SLIDE 12

x y full_join(x, y)

slide-13
SLIDE 13

id sex age 1 m 19 2 m 22 3 NA NA 4 f 19 5 f 18 id score 2 10 3 18 4 21 4 23 5 9 5 11 6 11 6 12 7 3

full_join(subject, exp)

id sex age score 1 m 19 NA 2 m 22 10 3 NA NA 18 4 f 19 21 4 f 19 23 5 f 18 9 5 f 18 11 6 NA NA 11 6 NA NA 12 7 NA NA 3

slide-14
SLIDE 14

x y semi_join(x, y)

*only columns from x; no duplicate rows, even if >1 match in y

slide-15
SLIDE 15

id sex age 1 m 19 2 m 22 3 NA NA 4 f 19 5 f 18 id score 2 10 3 18 4 21 4 23 5 9 5 11 6 11 6 12 7 3

semi_join(subject, exp)

id sex age 2 m 22 3 NA NA 4 f 19 5 f 18

slide-16
SLIDE 16

x y semi_join(y, x)

*only columns from y; no duplicate rows, even if >1 match in x

slide-17
SLIDE 17

id score 2 10 3 18 4 21 4 23 5 9 5 11

semi_join(exp, subject)

id sex age 1 m 19 2 m 22 3 NA NA 4 f 19 5 f 18 id score 2 10 3 18 4 21 4 23 5 9 5 11 6 11 6 12 7 3

slide-18
SLIDE 18

x y anti_join(x, y)

slide-19
SLIDE 19

id sex age 1 m 19 2 m 22 3 NA NA 4 f 19 5 f 18 id score 2 10 3 18 4 21 4 23 5 9 5 11 6 11 6 12 7 3

anti_join(subject, exp)

id sex age 1 m 19

slide-20
SLIDE 20

x y anti_join(y, x)

slide-21
SLIDE 21

anti_join(exp, subject)

id score 6 11 6 12 7 3 id sex age 1 m 19 2 m 22 3 NA NA 4 f 19 5 f 18 id score 2 10 3 18 4 21 4 23 5 9 5 11 6 11 6 12 7 3

slide-22
SLIDE 22

id sex age 1 m 19 2 m 22 3 NA NA 4 f 19 5 f 18

bind_rows(subject, new_subjects)

id sex age 6 m 19 7 m 16 8 f 20 9 f 19 id sex age 1 m 19 2 m 22 3 NA NA 4 f 19 5 f 18 6 m 19 7 m 16 8 f 20 9 f 19

+ =

slide-23
SLIDE 23

id sex age 1 m 19 2 m 22 3 NA NA 4 f 19 5 f 18

bind_cols(subject, new_info)

colour red

  • range

yellow green blue

+ =

id sex age colour 1 m 19 red 2 m 22 orange 3 NA NA yellow 4 f 19 green 5 f 18 blue

slide-24
SLIDE 24

id sex age 1 m 19 2 m 22 3 NA NA 4 f 19 5 f 18

intersect(subject, new_subjects)

id sex age 4 f 19 5 f 18 6 m 19 7 m 16 8 f 20 9 f 19 id sex age 4 f 19 5 f 18

=

slide-25
SLIDE 25

union(subject, new_subjects)

id sex age 4 f 19 5 f 18 6 m 19 7 m 16 8 f 20 9 f 19

=

id sex age 1 m 19 2 m 22 3 NA NA 4 f 19 5 f 18 6 m 19 7 m 16 8 f 20 9 f 19 id sex age 1 m 19 2 m 22 3 NA NA 4 f 19 5 f 18

slide-26
SLIDE 26

setdiff(subject, new_subjects)

id sex age 4 f 19 5 f 18 6 m 19 7 m 16 8 f 20 9 f 19

=

id sex age 1 m 19 2 m 22 3 NA NA id sex age 1 m 19 2 m 22 3 NA NA 4 f 19 5 f 18

slide-27
SLIDE 27

setdiff(new_subjects, subject)

id sex age 4 f 19 5 f 18 6 m 19 7 m 16 8 f 20 9 f 19

=

id sex age 1 m 19 2 m 22 3 NA NA 4 f 19 5 f 18 id sex age 6 m 19 7 m 16 8 f 20 9 f 19