Weather in Nanaimo
Test code starts here
# Load the MBAA531 package I created the MBAA 531 package directory and loaded the data set using the library function
library(MBAA531)
# Load the weather.Nanaimo dataset Similar to the above i loaded the specific data set by calling the data
data("weather.nanaimo")
# To verify the size and variables of the dataset i ran a summary query to have a view into the data set statistics
summary(weather.nanaimo)
## wind temp day
## Min. : 0.50 Min. : 52.00 Min. :2023-10-30
## 1st Qu.: 7.50 1st Qu.: 70.00 1st Qu.:2023-12-07
## Median :10.00 Median : 78.00 Median :2024-01-14
## Mean :10.03 Mean : 77.77 Mean :2024-01-14
## 3rd Qu.:13.10 3rd Qu.: 86.00 3rd Qu.:2024-02-21
## Max. :22.50 Max. :104.00 Max. :2024-03-30
# I wanted to confirm the total number of rows and columns the data set had so i used the dim function to view the dimension of the data.
dim(weather.nanaimo)
## [1] 153 3
# To explore the dataset further i used the head function to view the first 10 rows to confirm the values
head(weather.nanaimo, 10)
# To handle possible missing values in the dataset i ran the missing set functions to prevent future errors
missing_temp <- sum(is.na(weather.nanaimo$temperature) | is.nan(weather.nanaimo$temperature))
missing_wind <- sum(is.na(weather.nanaimo$wind) | is.nan(weather.nanaimo$wind))
# Print the results . I printed the result to confirm if there are any missing values
cat("Missing or NaN values in temperature:", missing_temp, "\n")
## Missing or NaN values in temperature: 0
cat("Missing or NaN values in wind:", missing_wind, "\n")
## Missing or NaN values in wind: 0
plot(weather.nanaimo$temp, weather.nanaimo$wind,
xlab = "Temperature (°C)", ylab = "Wind (km/h)",
main = "Relationship between Temperature and Wind in Nanaimo")
## From the plot it shows that the wind speed is decreasing as
temperature increases as observed a high point to a low point along the
y-axis, this suggests an inverse relationship between temperature and
wind speed in Nanaimo.
#There could be various reasons for this. #In Nanaimo, as temperatures rise, it could lead to changes in atmospheric conditions. Warmer temperatures may result in the air becoming less dense, which can create pressure differences between regions. Wind tends to flow from areas of higher pressure to areas of lower pressure, resulting in a decrease in wind speed as temperature increases. #Nanaimo’s local climate and geographical features may also be a factor that affects the relationship between temperature and wind speed.
I loaded the ant dataset from the directory
# Load the ants datasets
data("ants")
I am plotting the ant time series data set
plot(ants)
I am relabelling the ants time series graph to show the axis with the
ants nests height against the years
data("ants")
plot(ants,
xlab = "Year", ylab = "Ant Nests Height (inches)",
main = "Ant Nests Height Over Time")
Here i am writing the command to calculate the mean height of the ant
nests to compare against the maximum height
# Calculate the mean height of ant nests
mean_height <- mean(ants, na.rm = TRUE)
# Print the mean height
cat("The mean height of ant nests is:", mean_height, "inches\n")
## The mean height of ant nests is: 579.0101 inches
I am calculating and printing the maximum height of the ant nests
# Pick out the highest value from the heights of ant nests
highest_height <- max(ants)
# Print the highest value
cat("The highest height of ant nests is:", highest_height, "inches\n")
## The highest height of ant nests is: 582.04 inches
To find the year that has the maximum height i would like to explore the time series of the years. I am curious to know the range
# Inspect the structure of the loaded object
str(ants)
## Time-Series [1:98] from 1926 to 2023: 580 582 582 581 579 ...
Now i am finding the year in the series that has the maximum height
# Find the year with the highest height of 582.04
highest_year <- time(ants)[ants == 582.04]
# Print the highest year
cat("The year with the highest height of 582.04 is:", highest_year, "\n")
## The year with the highest height of 582.04 is: 1928
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.