library(dslabs)
data("murders")

2.Store the state names in a vectors?

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"

3.Store the state abberivation in a vectors?

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"

4.What is the total population of USA?

total_population_usa<-sum(murders$population)
total_population_usa
## [1] 309864228

5.how many murders have been done according to this dataset

total_murders<-sum(murders$total)
total_murders
## [1] 9403

6.which state has highest population?

highest_popuation_state<-murders$state[which.max(murders$population)]
highest_popuation_state
## [1] "California"

7.which state has highest no of murders?

highest_no_of_murders<-murders$state[which.max(murders$total)]
highest_no_of_murders
## [1] "California"

8.which state has lowest no of murders?

lowest_no_of_murders<-murders$state[which.min(murders$total)]
lowest_no_of_murders
## [1] "Vermont"

9.which state has lowest no of population?

lowest_no_of_population<-murders$state[which.min(murders$population)]
lowest_no_of_population
## [1] "Wyoming"

10.Display population of Washington?

washington_population<-murders$population[murders$state=='Washington']
cat(washington_population)
## 6724540

11.Display no of murders at Alaska?

no_of_murders_at_Alaska<-murders$total [murders$state=='Alaska'
] 
no_of_murders_at_Alaska
## [1] 19

12.compute correlation between population and number of murders.

Correlation:

      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.

Formula:

\[ 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}}}} \]

R Markdown

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

Including Plots

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.