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:
# Defining patient data
subject_name <- c("John Doe", "Jane Doe", "Steve Graves")
temperature <- c(98.1, 98.6, 101.4)
flu_status <- c(FALSE, FALSE, TRUE)
# Correcting factor assignment
gender <- factor(c("MALE", "FEMALE", "MALE"))
# Ensure levels match the values present
blood <- factor(c("O", "AB", "A"), levels = c("A", "B", "AB", "O"))
# Correcting case in blood sign factor
bloodsign <- factor(c("+", "-"), levels = c("+", "-"))
# Ordered factor with correct level sequence
symptoms <- factor(c("severe", "mild", "moderate"),
levels = c("mild", "moderate", "severe"),
ordered = TRUE)
# Correcting data frame creation
pt_data <- data.frame(subject_name, temperature, flu_status, gender, blood, symptoms,
stringsAsFactors = FALSE)
# Check the data frame
print(pt_data)
## subject_name temperature flu_status gender blood symptoms
## 1 John Doe 98.1 FALSE MALE O severe
## 2 Jane Doe 98.6 FALSE FEMALE AB mild
## 3 Steve Graves 101.4 TRUE MALE A moderate
pt_data$temp_c<-(pt_data$temperature-32)*(5/9)
pt_data
## subject_name temperature flu_status gender blood symptoms temp_c
## 1 John Doe 98.1 FALSE MALE O severe 36.72222
## 2 Jane Doe 98.6 FALSE FEMALE AB mild 37.00000
## 3 Steve Graves 101.4 TRUE MALE A moderate 38.55556
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.