Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Data Manipulation with dplyr (First Steps)

OmaymaS
November 08, 2018

Data Manipulation with dplyr (First Steps)

A workshop for beginners on the #tidyverse, focusing on data manipulation using #dplyr along with hands-on exercises.

Delivered at DataFest Tbilisi 2018.

OmaymaS

November 08, 2018
Tweet

More Decks by OmaymaS

Other Decks in Technology

Transcript

  1. id minion leader type age missions_ internal missions_ external 101

    yellow 5 60 2 102 yellow 6 55 10 108 purple 10 48 3 120 purple 16 49 1 100 yellow 3 54 4 > minions dataframe/tbl
  2. id minion leader type age missions_ internal missions_ external 101

    yellow 5 60 2 102 yellow 6 55 10 108 purple 10 48 3 120 purple 16 49 1 100 yellow 3 54 4 VARIABLES OBSERVATIONS
  3. Kevin_new <- rotate(kevin, direction = “clockwise”, angle = 90) object

    function arguments What is the value of Kevin_new ? kevin <-
  4. id minion leader type age missions_ internal missions_ external 101

    yellow 5 60 2 102 yellow 6 55 10 108 purple 10 48 3 120 purple 16 49 1 100 yellow 3 54 4 > minions
  5. id minion leader type age missions_ internal missions_ external 101

    yellow 5 60 2 102 yellow 6 55 10 108 purple 10 48 3 120 purple 16 49 1 100 yellow 3 54 4 id age 101 5 102 6 108 10 120 16 100 3 select(minions, id, age) New dataframe/tbl
  6. id minion leader type age missions_ internal 101 yellow 5

    60 102 yellow 6 55 108 purple 10 48 120 purple 16 49 100 yellow 3 54 select(minions, -missions_external)
  7. id minion leader type age missions_ internal missions_e xternal 101

    yellow 5 60 2 102 yellow 6 55 10 100 yellow 3 54 4 filter(minions, type == “yellow”)
  8. > < >= <= != == equal greater than less

    than greater than or equal less than or equal not equal MORE CONDITIONS & | AND OR COMBINE WITH ,
  9. id minion leader type age missions_ internal missions_e xternal 101

    yellow 5 60 2 102 yellow 6 55 10 filter(minions, type == “yellow” , age > 3)
  10. id minion leader type age missions_ internal missions_ external missions

    101 yellow 5 60 2 62 102 yellow 6 55 10 65 108 purple 10 48 3 51 120 purple 16 49 1 50 100 yellow 3 54 4 58 mutate(minions, missions = missions_internal+misssions_external)
  11. summarize(minions, age_median = median(age)) age_median 6 id minion leader type

    age missions_ internal missions_ external 101 yellow 5 60 2 102 yellow 6 55 10 108 purple 10 48 3 120 purple 16 49 1 100 yellow 3 54 4
  12. id minion leader type age missions_ internal missions_ external 108

    purple 10 48 3 120 purple 16 49 1 100 yellow 3 54 4 102 yellow 6 55 10 101 yellow 5 60 2 arrange(minions, missions_internal) DEFAULT Ascending
  13. id minion leader type age missions_ internal missions_ external 101

    yellow 5 60 2 102 yellow 6 55 10 100 yellow 3 54 4 120 purple 16 49 1 108 purple 10 48 3 arrange(minions, desc(missions_internal))
  14. <- scale( , 0.25) <- rotate( , “clockwise”, 90) <-

    clone( , 1) 1 2 3 Successive commands
  15. <- scale( , 0.25) 1 2 <- rotate( , “clockwise”,

    90) <- clone( , 1) 3 Successive commands