Import data

haunted_places <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2023/2023-10-10/haunted_places.csv')

Apply the following dplyr verbs to your data

Filter rows

filter(haunted_places, state == "California")
## # A tibble: 1,070 × 10
##    city       country description location state state_abbrev longitude latitude
##    <chr>      <chr>   <chr>       <chr>    <chr> <chr>            <dbl>    <dbl>
##  1 In Califo… United… "Y)"        (San M   Cali… CA               -122.     37.8
##  2 San Marcos United… "NO TRESSP… Harmony… Cali… CA                 NA      NA  
##  3 San Marcos United… "The ghost… Questha… Cali… CA               -117.     33.1
##  4 San Miguel United… "It has be… San Mig… Cali… CA               -121.     35.7
##  5 San Miguel United… "Adobe Com… San Mig… Cali… CA               -121.     35.7
##  6 San Rafael United… "There is … Dominic… Cali… CA               -123.     38.0
##  7 Sanger     United… "In the mi… Acacia … Cali… CA               -120.     36.7
##  8 Sanger     United… "Snake Roa… Centerv… Cali… CA               -120.     36.7
##  9 Sanger     United… "This is a… Hobbs G… Cali… CA               -120.     36.7
## 10 Santa Ana  United… "Popular t… Euclid … Cali… CA               -118.     33.8
## # ℹ 1,060 more rows
## # ℹ 2 more variables: city_longitude <dbl>, city_latitude <dbl>

Arrange rows

arrange(haunted_places, longitude, latitude)
## # A tibble: 10,992 × 10
##    city       country description location state state_abbrev longitude latitude
##    <chr>      <chr>   <chr>       <chr>    <chr> <chr>            <dbl>    <dbl>
##  1 Nightmute  United… "There is … Nightmu… Alas… AK               -165.     60.5
##  2 Kotzebue   United… "During th… NANA Mu… Alas… AK               -163.     66.9
##  3 Kauai      United… "Once upon… Lihue    Hawa… HI               -159.     22.0
##  4 Makaha     United… "Lights fl… Makaha … Hawa… HI               -158.     21.5
##  5 Makaha     United… "at night,… Makaha … Hawa… HI               -158.     21.5
##  6 O'ahu      United… "Reports t… Mokulei… Hawa… HI               -158.     21.6
##  7 Honolulu   United… "It was re… Barber'… Hawa… HI               -158.     21.3
##  8 Honolulu   United… "\"Firebal… Morgan'… Hawa… HI               -158.     21.5
##  9 North Sho… United… "There is … The Dro… Hawa… HI               -158.     21.6
## 10 Schofield… United… "Hearing m… J Quad … Hawa… HI               -158.     21.5
## # ℹ 10,982 more rows
## # ℹ 2 more variables: city_longitude <dbl>, city_latitude <dbl>

Select columns

select(haunted_places, state, latitude, longitude)
## # A tibble: 10,992 × 3
##    state    latitude longitude
##    <chr>       <dbl>     <dbl>
##  1 Michigan     43.0     -85.5
##  2 Michigan     42.0     -84.4
##  3 Michigan     41.9     -84.0
##  4 Michigan     41.9     -84.0
##  5 Michigan     42.2     -84.7
##  6 Michigan     42.2     -84.8
##  7 Michigan     NA        NA  
##  8 Michigan     42.7     -82.6
##  9 Michigan     42.5     -85.8
## 10 Michigan     42.5     -85.9
## # ℹ 10,982 more rows

Add columns

mutate(haunted_places,
       coordinates = longitude + latitude)
## # A tibble: 10,992 × 11
##    city       country description location state state_abbrev longitude latitude
##    <chr>      <chr>   <chr>       <chr>    <chr> <chr>            <dbl>    <dbl>
##  1 Ada        United… "Ada witch… Ada Cem… Mich… MI               -85.5     43.0
##  2 Addison    United… "A little … North A… Mich… MI               -84.4     42.0
##  3 Adrian     United… "If you ta… Ghost T… Mich… MI               -84.0     41.9
##  4 Adrian     United… "In the 19… Siena H… Mich… MI               -84.0     41.9
##  5 Albion     United… "Kappa Del… Albion … Mich… MI               -84.7     42.2
##  6 Albion     United… "A mysteri… Riversi… Mich… MI               -84.8     42.2
##  7 Algoma To… United… "On a wind… Hell's … Mich… MI                NA       NA  
##  8 Algonac    United… "Morrow Ro… Morrow … Mich… MI               -82.6     42.7
##  9 Allegan    United… "People re… Elks Lo… Mich… MI               -85.8     42.5
## 10 Allegan    United… "Various g… The Gri… Mich… MI               -85.9     42.5
## # ℹ 10,982 more rows
## # ℹ 3 more variables: city_longitude <dbl>, city_latitude <dbl>,
## #   coordinates <dbl>

Summarize by groups

haunted_places %>%
    
    # Group by State
    group_by(state) %>%
    summarise(count = n())
## # A tibble: 51 × 2
##    state       count
##    <chr>       <int>
##  1 Alabama       224
##  2 Alaska         32
##  3 Arizona       156
##  4 Arkansas      119
##  5 California   1070
##  6 Colorado      166
##  7 Connecticut   185
##  8 Delaware       37
##  9 Florida       328
## 10 Georgia       289
## # ℹ 41 more rows
haunted_places %>%
    # Group by city
    group_by(city)%>%
    summarise(count = n())
## # A tibble: 4,386 × 2
##    city        count
##    <chr>       <int>
##  1 <>Manteca       1
##  2 ARNOLD          1
##  3 Abbeville       1
##  4 Abercrombie     1
##  5 Aberdeen        6
##  6 Abilene         4
##  7 Abingdon        2
##  8 Absecon         1
##  9 Academia        3
## 10 Ackley          1
## # ℹ 4,376 more rows
haunted_places %>%
    # Group by state and city
    group_by(city, state)%>%
    summarise(count = n())
## # A tibble: 5,457 × 3
## # Groups:   city [4,386]
##    city        state          count
##    <chr>       <chr>          <int>
##  1 <>Manteca   California         1
##  2 ARNOLD      Missouri           1
##  3 Abbeville   South Carolina     1
##  4 Abercrombie North Dakota       1
##  5 Aberdeen    Maryland           1
##  6 Aberdeen    North Carolina     1
##  7 Aberdeen    Ohio               1
##  8 Aberdeen    South Dakota       2
##  9 Aberdeen    Washington         1
## 10 Abilene     Texas              4
## # ℹ 5,447 more rows