mean(head(sort(airquality$Ozone), 10))
. Describe in one sentence what the effect of this command is.sort()
has an optional parameter decreasing
to control the ordering direction.Solar.R
in the built-in data set airquality
. Use the function sd()
for this and set it to ignore NA
values in the input vector.rnorm()
is a function to generate random numbers from a normal distribution. Find out which parameters it has using R’s built-in help function. Now generate 100 random numbers from a normal distribution with mean 30 and standard deviation 2. Calculate the mean from these numbers. How much differs the mean of your generated numbers from the mean 30?MASS
and its data set cats
as in the previous session. Answer the following questions (Hint: Create a logical expression and use sum()
to count the occurrences of TRUE
values, e.g. sum(cats$Sex == 'F')
):
n_female
and n_male
.Example 1:
sum(airquality$Month = 5)
## Error
Example 2:
smoker <- c(TRUE, NA, FALSE, TRUE, FALSE)
sum(smoker, na.rm <- TRUE)
## Error
Example 3:
age <- c(20, NA, 19, 51, 20)
mean(age, na.rm == TRUE)
## Error
Example 4:
country <- factor(c('USA', 'GB', 'GB', 'DE', 'USA'))
country_is_usa <- (country = 'USA')
country_is_usa
## [1] "USA"
Example 5:
age <- c(20, NA, 19, 51, 20)
median(age, rm.na = TRUE)
## [1] NA