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,NA)
#find mean.
result.mean <- mean(x)
print(result.mean)
## [1] NA
#find mean dropping NA values.
result.mean <- mean(x,na.rm= TRUE)
print(result.mean)
## [1] 8.22
result.mean <- mean(x,na.rm= FALSE)
print(result.mean)
## [1] NA
#find median.
median(x)
## [1] NA
median(x,na.rm=TRUE)
## [1] 5.6
library(readr)
# Load the renamed file
ChildrenAsthma_Survey <- read_csv("C:/Users/yeu3178/Downloads/ChildrenAsthmaSurvey.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`
# Check if it loaded correctly
head(ChildrenAsthma_Survey)
## # A tibble: 6 × 9
## ...1 Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 13 2 1 1 2 1 3 1
## 2 2 5 2 4 1 3 1 3 0
## 3 3 7 1 5 1 1 1 6 1
## 4 4 14 2 6 1 4 9 1 0
## 5 5 6 1 6 1 5 0 1 0
## 6 6 2 1 5 1 1 1 6 1
#find mode
mode(x)
## [1] "numeric"
library(tibble)
CAS <- ChildrenAsthma_Survey # Use the correct variable name
View(CAS)
table(CAS$Q2)
##
## 1 2
## 10 10
prop.table(table(CAS$Q2))
##
## 1 2
## 0.5 0.5
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
communityChildAsthma<-(600/54786)*1000
print(communityChildAsthma)
## [1] 10.9517
# Ensure CAS is a dataframe
AA <- CAS[CAS$Q3 == 5, ] # Subset rows where Q3 equals 5
# Create a frequency table for Q5 in the filtered data
table(AA$Q5)
##
## 1 3
## 3 2
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
prop.table(table(AA$Q5))
##
## 1 3
## 0.6 0.4
prop.table(table(AA$Q5!=5))
##
## TRUE
## 1
table(table(AA$Q5!=5))
##
## 5
## 1
white <- CAS[CAS$Q3 == 6, ]
table(white$Q5)
##
## 1 4 5
## 2 1 1
prop.table(table(AA$Q5))
##
## 1 3
## 0.6 0.4
prop.table(table(AA$Q5!=5))
##
## TRUE
## 1
table(table(AA$Q5!=5))
##
## 5
## 1
table(AA$Q2)
##
## 1 2
## 4 1
AA$Q2
## [1] 1 1 1 1 2
table(AA$Q4)
##
## 1
## 5
prop.table(AA$Q4)*100
## [1] 20 20 20 20 20
prop.table(table(AA$Q4))*100
##
## 1
## 100
WK <- CAS[CAS$Q3 == 6, ] # White kids
table(WK$Q4)
##
## 1
## 4
table(WK$Q5)
##
## 1 4 5
## 2 1 1
prop.table(table(WK$Q5))
##
## 1 4 5
## 0.50 0.25 0.25
LK <- CAS[CAS$Q3 == 3, ] # Latino Kids (assuming Q3 == 3 means Latino)
table(LK$Q4)
##
## 1
## 2
table(LK$Q5)
##
## 3
## 2
prop.table(table(LK$Q5))
##
## 3
## 1
AK <- CAS[CAS$Q3 == 4, ] # Asian Kids (assuming Q3 == 4 means Asian)
table(AK$Q4)
##
## 1
## 3
table(AK$Q5)
##
## 1 3 4
## 1 1 1
prop.table(table(AK$Q5))
##
## 1 3 4
## 0.3333333 0.3333333 0.3333333
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.