We measure p variables for two observations: xj is the measurement of variable j for observation x, yj is the measurement of variable j for observation y. Euclidean distance between x and y is:
D(x,y)= ⎷p∑j=1(xj−yj)2
D(x,y)=p∑j=1∣∣xj−yj∣∣
dist
objectdist
objectdist()
functiondist
objectdist()
functiondist
objectdist()
functiondist
to get the distances.library(dplyr)Beer<-readRDS('Beer.rds')
Beer%>%filter(price>4.5)%>% #Only expensive Beers select_if(is.numeric)%>% #Only numeric variables scale%>% dist->d
1 | 2 | 3 | 4 | 5 |
---|---|---|---|---|
0.0000 | 3.4298 | 3.8333 | 4.1632 | 4.1950 |
3.4298 | 0.0000 | 2.3009 | 2.8076 | 1.6260 |
3.8333 | 2.3009 | 0.0000 | 1.1482 | 3.2339 |
4.1632 | 2.8076 | 1.1482 | 0.0000 | 3.3188 |
4.1950 | 1.6260 | 3.2339 | 3.3188 | 0.0000 |
dist
object.attributes(d)$Labels
d
is the dist
object.Beer%>%filter(price>4.5)%>% #Only expensive Beers pull(beer)-> #Get beer names attributes(d)$Labels #"Attach" them to dist object
Anchor Steam | Becks | Heineken | Kirin | St Pauli Girl | |
---|---|---|---|---|---|
Anchor Steam | 0.0000 | 3.4298 | 3.8333 | 4.1632 | 4.1950 |
Becks | 3.4298 | 0.0000 | 2.3009 | 2.8076 | 1.6260 |
Heineken | 3.8333 | 2.3009 | 0.0000 | 1.1482 | 3.2339 |
Kirin | 4.1632 | 2.8076 | 1.1482 | 0.0000 | 3.3188 |
St Pauli Girl | 4.1950 | 1.6260 | 3.2339 | 3.3188 | 0.0000 |
Figure by Mohamed Ben Ellefi
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |