convert_temperature <- function(value, from_unit, to_unit) {
if (from_unit == "C" & to_unit == "F") {
return((value * 9/5) + 32)
} else if (from_unit == "F" & to_unit == "C") {
return((value - 32) * 5/9)
} else if (from_unit == "C" & to_unit == "K") {
return(value + 273.15)
} else if (from_unit == "K" & to_unit == "C") {
return(value - 273.15)
} else if (from_unit == "F" & to_unit == "K") {
return((value - 32) * 5/9 + 273.15)
} else if (from_unit == "K" & to_unit == "F") {
return((value - 273.15) * 9/5 + 32)
} else {
return("Invalid input! Please use 'C', 'F', or 'K' as units.")
}
}
# Example usage:
convert_temperature(100, "C", "F") # Converts 100°C to Fahrenheit
## [1] 212
convert_temperature(32, "F", "C") # Converts 32°F to Celsius
## [1] 0
convert_temperature(0, "C", "K") # Converts 0°C to Kelvin
## [1] 273.15
library(readr)
ChildrenAsthma_Survey <- read_csv("/Users/deveonwright/Documents/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)
mean(CAS$Q1)
## [1] 9.1
table(CAS$Q2)
##
## 1 2
## 10 10
prop.table(table(CAS$Q2))
##
## 1 2
## 0.5 0.5
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
communityChildAsthma <- (600/54786)*1000
print(communityChildAsthma)
## [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
## Help on topic 'table' was found in the following packages:
##
## Package Library
## vctrs /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library
## base /Library/Frameworks/R.framework/Resources/library
##
##
## Using the first match ...
table(AA$Q5)
##
## 1 3
## 3 2
print(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 != 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
WK <- CAS[CAS$Q3==6,]
WK
## # A tibble: 4 × 9
## ...1 Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 4 14 2 6 1 4 9 1 0
## 2 5 6 1 6 1 5 0 1 0
## 3 14 16 1 6 1 1 1 5 1
## 4 20 12 1 6 1 1 1 4 1
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==1,]
LK
## # A tibble: 3 × 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 10 8 2 1 1 2 1 1 9
## 3 11 7 1 1 1 2 1 3 9
table(LK$Q4)
##
## 1
## 3
table(LK$Q5)
##
## 2
## 3
prop.table(table(LK$Q5))
##
## 2
## 1
x <- c(12,7,3,4.2,18,2,54,-21,8,-5)
result.mean <- mean(x)
print(result.mean)
## [1] 8.22
result.mean <- mean(x,trim = 0.3)
print(result.mean)
## [1] 5.55
x <- c(12,7,3,4.2,18,2,54,-24,8,-5,NA)
result.mean <- mean(x,na.rm = FALSE)
print(result.mean)
## [1] NA
median(x)
## [1] NA
median(x,na.rm = TRUE)
## [1] 5.6
library(readr)
ChildrenAsthma_Survey <- read_csv("/Users/deveonwright/Documents/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)
mean(CAS$Q1)
## [1] 9.1
table(CAS$Q2)
##
## 1 2
## 10 10
prop.table(table(CAS$Q2))
##
## 1 2
## 0.5 0.5
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
communityChildAsthma <- (600/54786)*1000
print(communityChildAsthma)
## [1] 10.9517