Chapter 4 Data Transformation

We’d like to order the data by average_review to see the general ranking of the restaurants.

##                              name                           street_address
## 274 Il Mulino New York - Downtown   86 West 3rd Street New York, NY  10012
## 285               The Musket Room 265 Elizabeth St. CI New York, NY  10012
## 6           Estiatorio Milos - NY 125 West 55th Street New York, NY  10019
## 260                      Perry St     176 Perry Street New York, NY  10014
## 130     Benjamin Steakhouse Prime        23 E 40th St. New York, NY  10016
## 108             Club A Steakhouse 240 East 58th Street New York, NY  10022
##                                                            google_map
## 274 //www.google.com/maps/search/?api=1&query=40.7298290%2C-73.999091
## 285 //www.google.com/maps/search/?api=1&query=40.7238560%2C-73.993735
## 6   //www.google.com/maps/search/?api=1&query=40.7634560%2C-73.978894
## 260   //www.google.com/maps/search/?api=1&query=40.7346000%2C-74.0093
## 130 //www.google.com/maps/search/?api=1&query=40.7514370%2C-73.979977
## 108  //www.google.com/maps/search/?api=1&query=40.7605260%2C-73.96609
##     review_count          phone                            website
## 274          830 (212) 673-3783           http://www.ilmulino.com/
## 285          768 (212) 219-0764         http://www.musketroom.com/
## 6           4404 (212) 245-7400    http://www.estiatoriomilos.com/
## 260         3657 (212) 352-1900  http://www.perrystrestaurant.com/
## 130          356 (212) 338-0818 http://www.benjaminsteakhouse.com/
## 108         3371 (212) 688-4190        http://clubasteakhouse.com/
##           restaurant_type average_review food_review service_review
## 274               Italian        4.88300         4.7            4.8
## 285         International        4.87680         4.7            4.7
## 6                 Seafood        4.84404         4.8            4.6
## 260 Contemporary American        4.83657         4.7            4.7
## 130              American        4.83560         4.7            4.8
## 108            Steakhouse        4.83371         4.7            4.8
##     ambience_review value_review  price_range star_1 star_2 star_3 star_4
## 274             4.6          4.4 $50 and over      1      2      2      5
## 285             4.6          4.2   $31 to $50      0      1      3     15
## 6               4.6          4.2 $50 and over      1      1      3     14
## 260             4.6          4.3   $31 to $50      1      2      2     11
## 130             4.6          4.3 $50 and over      0      1      4     13
## 108             4.7          4.6   $31 to $50      1      1      4     10
##     star_5
## 274     90
## 285     81
## 6       81
## 260     84
## 130     82
## 108     84
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       description
## 274                                                                                                                                                                                                                                                                                                                                                         For nearly 35 years, Il Mulino New York has prepared authentic Abruzzese cuisine with unparalleled service.There<U+00A1><U+00AF>s no place like Il Mulino New York. The luxury Italian restaurant<U+00A1><U+00AF>s flagship Greenwich Village outpost initiated New York<U+00A1><U+00AF>s fine Italian dining trend and is still prized in the city<U+00A1><U+00AF>s elite dining scene. Zagat has rated Il Mulino New York as Manhattan<U+00A1><U+00AF>s No. 1 Italian restaurant for decades and has said the restaurant provides "one-of-a-kind" cuisine filled with delicious flavors, creating an "outstanding Italian classic" restaurant where "every dish is a masterpiece." 
## 285 The Musket Room brings the spirit of New Zealand and the country<U+00A1><U+00AF>s diverse cuisine to Manhattan<U+00A1><U+00AF>s Nolita neighborhood. Chef and owner Matt Lambert, a New Zealand native, created a menu that charts the evolution of New Zealand cuisine, from the country<U+00A1><U+00AF>s Old World traditions and Asian influences to its modern day dedication to local and seasonal offerings. Inspired by an era in New Zealand when adventure and discovery blossomed, The Musket Room offers a modern approach to the country<U+00A1><U+00AF>s culinary past, serving dinner and drinks.Reservations made through Opentable will secure you a reservation in either the main dining room or garden room, where we offer both a la carte  and the short  tasting menu. The tasting menu must be booked in advance. Please let us know if you or any of your guests have an allergy or dietary restriction. We can accommodate for vegetarians with our tasting menu and al a carte for vegan diners with 24hr notice.  
## 6                                                                                                                                                                                                                                                                                                                                                                                                                                                                      The freshest, most flavorful fish, vegetables / fruits, prepared in the subtlest way and served in an elegant, spacious setting, is why Milo's has become of one of New York's most lauded restaurant. Costas Spiliadis, owner/chef, is continuing the standard of excellence he began in Montreal, where he opened the original Milos, now a landmark. Patrons can choose their fish from an abundant market display and watch it swiftly grilled in the open kitchen.  Pre-fixe menu 5pm to 6pm  Monday to Saturday, Late night menu 10pm to closing Monday to Saturday.
## 260                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 Chef Jean-Georges brings relaxed elegance to the West Village with Perry St - awarded three stars by the New York Times. Jean-Georges<U+00A1><U+00AF> son, Cedric Vongerichten, helms the kitchen, creating dishes that reflect his own keen instinct for balancing flavor and texture with an exquisite blend of French, American, and Asian influences and ingredients. The menu is inspired by the season, centering on the local market at Union Square. Please visit us http://www.perrystrestaurant.com for menus and more information.
## 130                                                                                                                                                                                                              After ten years of continued success in the New York metro area, Benjamin Restaurant Group is proud to open its newest space, Benjamin Steakhouse Prime. Here, modern elegance is combined with traditional steakhouse classics, while also showcasing signature standouts from highly regarded sister property Benjamin Steakhouse. After perfecting both steakhouse and seafood concepts in their arsenal, Benjamin Restaurant Group is highlighting the grill at Prime, serving up USDA prime dry aged steaks and succulent seafood in unique ways. The 10,000 square foot space houses an expansive main dining room featuring wall mounted fireplaces. A temperature-controlled wine wall is exposed throughout the upper level which also offers five customizable private dining spaces for seating of up to 100+ guests.
## 108                                                                                                                                                                                                                                                                                                                                                                                                                                                 Club A Steakhouse provides a truly unique dining experience. Family owned and operated the owner Bruno Selimaj or one of his three sons are onsite and greets each guest every night. Club A manages to encompass the characteristics of a traditional steak house and new world modernism that is evident in both the menu and d<U+00A8><U+00A6>cor. The warmth paired with the distinct menu and extensive wine list make it perfect for any occasion. Please note that Club A Steakhouse will honor your Groupon reservations however OpenTable Diner Rewards points will not be received.
##      restaurant_main_type latitude longitude postal_code
## 274               Italian 40.72977 -73.99914       10012
## 285                 Other 40.72393 -73.99382       10012
## 6                 Seafood 40.76360 -73.97895       10019
## 260 Contemporary American 40.73443 -74.00970       10014
## 130              American 40.75150 -73.97993       10016
## 108            Steakhouse 40.76005 -73.96558       10022

We’d like to join our datasets to see both the violations and the ratings. To accomplish that, we first convert all restaurants names to lower cases with tolower(), then strip symbols off on two datasets with sub() to create uniform syntax for names. After that, we used sqldf package to count the number of violations each restaurant has and join the two datasets together as our final dataset.

We can take a glance at the final dataset.

##                        name                           street_address
## 1           the musket room 265 Elizabeth St. CI New York, NY  10012
## 2 benjamin steakhouse prime        23 E 40th St. New York, NY  10016
## 3         club a steakhouse 240 East 58th Street New York, NY  10022
##                                                          google_map
## 1 //www.google.com/maps/search/?api=1&query=40.7238560%2C-73.993735
## 2 //www.google.com/maps/search/?api=1&query=40.7514370%2C-73.979977
## 3  //www.google.com/maps/search/?api=1&query=40.7605260%2C-73.96609
##   review_count          phone                            website
## 1          768 (212) 219-0764         http://www.musketroom.com/
## 2          356 (212) 338-0818 http://www.benjaminsteakhouse.com/
## 3         3371 (212) 688-4190        http://clubasteakhouse.com/
##   restaurant_type average_review food_review service_review ambience_review
## 1   International        4.87680         4.7            4.7             4.6
## 2        American        4.83560         4.7            4.8             4.6
## 3      Steakhouse        4.83371         4.7            4.8             4.7
##   value_review  price_range star_1 star_2 star_3 star_4 star_5
## 1          4.2   $31 to $50      0      1      3     15     81
## 2          4.3 $50 and over      0      1      4     13     82
## 3          4.6   $31 to $50      1      1      4     10     84
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     description
## 1 The Musket Room brings the spirit of New Zealand and the country<U+00A1><U+00AF>s diverse cuisine to Manhattan<U+00A1><U+00AF>s Nolita neighborhood. Chef and owner Matt Lambert, a New Zealand native, created a menu that charts the evolution of New Zealand cuisine, from the country<U+00A1><U+00AF>s Old World traditions and Asian influences to its modern day dedication to local and seasonal offerings. Inspired by an era in New Zealand when adventure and discovery blossomed, The Musket Room offers a modern approach to the country<U+00A1><U+00AF>s culinary past, serving dinner and drinks.Reservations made through Opentable will secure you a reservation in either the main dining room or garden room, where we offer both a la carte  and the short  tasting menu. The tasting menu must be booked in advance. Please let us know if you or any of your guests have an allergy or dietary restriction. We can accommodate for vegetarians with our tasting menu and al a carte for vegan diners with 24hr notice.  
## 2                                                                                                                                                                                                              After ten years of continued success in the New York metro area, Benjamin Restaurant Group is proud to open its newest space, Benjamin Steakhouse Prime. Here, modern elegance is combined with traditional steakhouse classics, while also showcasing signature standouts from highly regarded sister property Benjamin Steakhouse. After perfecting both steakhouse and seafood concepts in their arsenal, Benjamin Restaurant Group is highlighting the grill at Prime, serving up USDA prime dry aged steaks and succulent seafood in unique ways. The 10,000 square foot space houses an expansive main dining room featuring wall mounted fireplaces. A temperature-controlled wine wall is exposed throughout the upper level which also offers five customizable private dining spaces for seating of up to 100+ guests.
## 3                                                                                                                                                                                                                                                                                                                                                                                                                                                 Club A Steakhouse provides a truly unique dining experience. Family owned and operated the owner Bruno Selimaj or one of his three sons are onsite and greets each guest every night. Club A manages to encompass the characteristics of a traditional steak house and new world modernism that is evident in both the menu and d<U+00A8><U+00A6>cor. The warmth paired with the distinct menu and extensive wine list make it perfect for any occasion. Please note that Club A Steakhouse will honor your Groupon reservations however OpenTable Diner Rewards points will not be received.
##   restaurant_main_type latitude longitude postal_code violation_count
## 1                Other 40.72393 -73.99382       10012               7
## 2             American 40.75150 -73.97993       10016               8
## 3           Steakhouse 40.76005 -73.96558       10022               7

While the above final dataset contains information about restaurants which had violation records, in order to faciliate the interaction part of this project, we are going to create cleaned_restaurants and cleaned_violations datasets, so that we can 1.find each restaruant’s violation total count (including 0) 2.boil down the large original violations file so the new file only contains restaurant week’s restaurants’ specific violation information.