library(dslabs)
data("murders")
state<-c(murders$state)
state
## [1] "Alabama" "Alaska" "Arizona"
## [4] "Arkansas" "California" "Colorado"
## [7] "Connecticut" "Delaware" "District of Columbia"
## [10] "Florida" "Georgia" "Hawaii"
## [13] "Idaho" "Illinois" "Indiana"
## [16] "Iowa" "Kansas" "Kentucky"
## [19] "Louisiana" "Maine" "Maryland"
## [22] "Massachusetts" "Michigan" "Minnesota"
## [25] "Mississippi" "Missouri" "Montana"
## [28] "Nebraska" "Nevada" "New Hampshire"
## [31] "New Jersey" "New Mexico" "New York"
## [34] "North Carolina" "North Dakota" "Ohio"
## [37] "Oklahoma" "Oregon" "Pennsylvania"
## [40] "Rhode Island" "South Carolina" "South Dakota"
## [43] "Tennessee" "Texas" "Utah"
## [46] "Vermont" "Virginia" "Washington"
## [49] "West Virginia" "Wisconsin" "Wyoming"
abb<-c(murders$abb)
abb
## [1] "AL" "AK" "AZ" "AR" "CA" "CO" "CT" "DE" "DC" "FL" "GA" "HI" "ID" "IL" "IN"
## [16] "IA" "KS" "KY" "LA" "ME" "MD" "MA" "MI" "MN" "MS" "MO" "MT" "NE" "NV" "NH"
## [31] "NJ" "NM" "NY" "NC" "ND" "OH" "OK" "OR" "PA" "RI" "SC" "SD" "TN" "TX" "UT"
## [46] "VT" "VA" "WA" "WV" "WI" "WY"
total_population_usa<-sum(murders$population)
total_population_usa
## [1] 309864228
total_murders<-sum(murders$total)
total_murders
## [1] 9403
highest_popuation_state<-murders$state[which.max(murders$population)]
highest_popuation_state
## [1] "California"
highest_no_of_murders<-murders$state[which.max(murders$total)]
highest_no_of_murders
## [1] "California"
lowest_no_of_murders<-murders$state[which.min(murders$total)]
lowest_no_of_murders
## [1] "Vermont"
lowest_no_of_population<-murders$state[which.min(murders$population)]
lowest_no_of_population
## [1] "Wyoming"
washington_population<-murders$population[murders$state=='Washington']
cat(washington_population)
## 6724540
no_of_murders_at_Alaska<-murders$total [murders$state=='Alaska'
]
no_of_murders_at_Alaska
## [1] 19
Correlation is a statistical measure that describes the degree to which two or more variables are related or associated with each other. It quantifies the strength and direction of the linear relationship between these variables.
\[ r = \frac{{\sum{(x_i - \bar{x})(y_i - \bar{y})}}}{{\sqrt{\sum{(x_i - \bar{x})^2} \cdot \sum{(y_i - \bar{y})^2}}}} \]
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.