Primary exercises
- For weight and height measurements we have the
metric
(cm,kg) and imperial
(inch,lbs) systems. The relation
between the measurements in different systems is (1 kg = 2.2 lbs) and (1
inch = 2.54 cm). Write the following unit conversion functions:
- cm2meter : convert cm to meter
- lbs2kg : convert weight unit pound to kg
- inch2cm : convert inch to cm
# Some example calls to the functions:
> inch2cm(70)
[1] 177.8
> lbs2kg(10)
[1] 4.545455
> cm2m(190)
[1] 1.9
cm2m <- function(x) x*0.01 # cm to meter
lbs2kg <- function(x) x/2.2 # pound to kg
inch2cm <- function(x) x*2.54 # inch to cm
- Write a function for the survey dataset to report a summary on
average pulse and the number of individuals in the given age range. Call
it
ageRangePulseSummary
and it should take 3 arguments, the
survey data, minimum age and maximum age, for example:
ageRangePulseSummary <- function(x, lowerBound,upperBound) {
x %>% filter(age >= lowerBound & age < upperBound) %>%
summarise(meanpulse=mean(pulse, na.rm = TRUE),individuals=n())
}
ageRangePulseSummary(survey, 16,17)
# A tibble: 1 × 2
meanpulse individuals
<dbl> <int>
1 76.2 4
- Take the function
weightRangeSummary
in the lecture
notes, make the necessary update such that it includes the weight
intervals.
weightRangeSummary <- function(x, lowerBound,upperBound) {
x %>% filter(weight >= lowerBound & weight < upperBound) %>%
summarise(meanHeight=mean(height),
increasedPulse=sum(pulse1<pulse2, na.rm = TRUE),
weightLowerBound=lowerBound,
weightUpperBound=upperBound,
individuals=n())
}
Copyright © 2023 Biomedical Data Sciences (BDS) | LUMC