set up
library(tidyverse)
## -- Attaching packages -------------------------------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2 v purrr 0.3.4
## v tibble 3.0.1 v dplyr 1.0.0
## v tidyr 1.1.0 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.5.0
## -- Conflicts ----------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
murders <-read_csv("murders.csv")
## Warning: Missing column names filled in: 'X1' [1]
## Parsed with column specification:
## cols(
## X1 = col_double(),
## state = col_character(),
## abb = col_character(),
## region = col_character(),
## population = col_double(),
## total = col_double(),
## murder_per_capita = col_double()
## )
Try Mutate
murder_per_hundred_thou <- mutate(murders, murder_per_hundred_thou = population / 100000)
auto_specs_new <- mutate(auto_specs, hp_to_weight = horsepower / weight)
write.csv (murder_per_hundred_thou, file = "murder_per_hundred_thou")
murder_per_hundred_thou
## # A tibble: 51 x 8
## X1 state abb region population total murder_per_capi~ murder_per_hund~
## <dbl> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
## 1 1 Alabama AL South 4779736 135 0.0000282 47.8
## 2 2 Alaska AK West 710231 19 0.0000268 7.10
## 3 3 Arizona AZ West 6392017 232 0.0000363 63.9
## 4 4 Arkans~ AR South 2915918 93 0.0000319 29.2
## 5 5 Califo~ CA West 37253956 1257 0.0000337 373.
## 6 6 Colora~ CO West 5029196 65 0.0000129 50.3
## 7 7 Connec~ CT North~ 3574097 97 0.0000271 35.7
## 8 8 Delawa~ DE South 897934 38 0.0000423 8.98
## 9 9 Distri~ DC South 601723 99 0.000165 6.02
## 10 10 Florida FL South 19687653 669 0.000034 197.
## # ... with 41 more rows