library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
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:
# Load the dataset from the specified path
dp_df <- read.csv("C:/Users/pulud/Downloads/bloodpressuredrug.csv")
# View the first few rows of the dataset
head(dp_df)
## Blood.pressure Drug
## 1 128 Drug A
## 2 130 Drug A
## 3 132 Drug A
## 4 135 Drug A
## 5 129 Drug A
## 6 130 Drug A
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:
# Run summary statistics on the entire dataset
summary(dp_df)
## Blood.pressure Drug
## Min. :128.0 Length:90
## 1st Qu.:133.0 Class :character
## Median :136.0 Mode :character
## Mean :136.4
## 3rd Qu.:139.0
## Max. :145.0
# Group by Drug type and calculate mean, variance, standard deviation, max, and min for Blood pressure
dp_summary <- dp_df %>%
group_by(Drug) %>%
summarize(
Mean = mean(Blood.pressure, na.rm = TRUE),
Variance = var(Blood.pressure, na.rm = TRUE),
SD = sd(Blood.pressure, na.rm = TRUE),
Max = max(Blood.pressure, na.rm = TRUE),
Min = min(Blood.pressure, na.rm = TRUE)
)
# Display the summary statistics grouped by Drug
dp_summary
## # A tibble: 3 × 6
## Drug Mean Variance SD Max Min
## <chr> <dbl> <dbl> <dbl> <int> <int>
## 1 Drug A 133. 8.34 2.89 139 128
## 2 Drug B 139. 15.9 3.99 145 131
## 3 Drug C 137 13.9 3.73 145 130
plot(pressure)
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.
# Carry out the ANOVA analysis to compare Blood pressure across different Drug types
dpAnova <- aov(Blood.pressure ~ Drug, data = dp_df)
# Display the summary of the ANOVA
summary(dpAnova)
## Df Sum Sq Mean Sq F value Pr(>F)
## Drug 2 513.3 256.63 20.17 6.35e-08 ***
## Residuals 87 1106.8 12.72
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1