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:

#Create a vector.
x <- c(12,7,3,4.2,18,2,54,-21,8,-5)

#Find Mean
result.mean <- mean(x)
print(result.mean)
## [1] 8.22
#using trim to drop values from the end of the calculation
result.mean <- mean (x,trim = 0.3)
print(result.mean)
## [1] 5.55
#Find mean dropping NA values.
x <- c(12,7,3,4.2,18,2,54,-21,8,-5,NA)
result.mean<- mean(x,na.rm = FALSE)
print(result.mean)
## [1] NA
#Syntax for calculating median
median(x)
## [1] NA
median(x, na.rm = TRUE)
## [1] 5.6
library(readr)
ChildrenAsthma_Survey <- read_csv("C:/Users/ijiol/OneDrive/Documents/R projects/R for Advanced Topics/Datasets/ChildrenAsthma Survey.csv")
## New names:
## Rows: 20 Columns: 9
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," dbl
## (9): ...1, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `` -> `...1`
View(ChildrenAsthma_Survey)
CAS <-ChildrenAsthma_Survey
#View(CAS)
#Average age of the participants children
avg_age = mean(CAS$Q1)
avg_age
## [1] 9.1
table(CAS$Q2)
## 
##  1  2 
## 10 10
#
prop.table(table(CAS$Q2))
## 
##   1   2 
## 0.5 0.5
# no of children by race
table(CAS$Q3)
## 
## 1 2 3 4 5 6 7 
## 3 2 2 3 5 4 1
prop.table(table(CAS$Q3))
## 
##    1    2    3    4    5    6    7 
## 0.15 0.10 0.10 0.15 0.25 0.20 0.05
#rate of asthma 
Asthma_Rate <- (600/54786)*1000
print(Asthma_Rate)
## [1] 10.9517
AA <- CAS[CAS$Q3 == 5, ]
AA
## # A tibble: 5 × 9
##    ...1    Q1    Q2    Q3    Q4    Q5    Q6    Q7    Q8
##   <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1     3     7     1     5     1     1     1     6     1
## 2     6     2     1     5     1     1     1     6     1
## 3    12     3     1     5     1     1     1     5     0
## 4    13     4     1     5     1     3     1     3     0
## 5    19    11     2     5     1     3     0     4     0
table(AA$Q5)
## 
## 1 3 
## 3 2
prop.table(table(AA$Q5))
## 
##   1   3 
## 0.6 0.4
prop.table(table(AA$Q5 != 5))
## 
## TRUE 
##    1
table(AA$Q5 !=5)
## 
## TRUE 
##    5
table(AA$Q2)
## 
## 1 2 
## 4 1
AA$Q2
## [1] 1 1 1 1 2
table(AA$Q4)
## 
## 1 
## 5
prop.table(table(AA$Q4)) * 100
## 
##   1 
## 100
WA <- CAS[CAS$Q3==6,]


table(WA$Q5)
## 
## 1 4 5 
## 2 1 1
prop.table(table(WA$Q5))
## 
##    1    4    5 
## 0.50 0.25 0.25
LA <- CAS[CAS$Q3==1, ]
prop.table(table(LA$Q5))
## 
## 2 
## 1

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.