University of Sydney · FACULTY OF ENGINEERING

CIVL6001 Chap.6 R Foundations for Climate Data

- one subject, every graph, every model, every mark
6 Chapters3-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 6 of 8 · CIVL6001

R Foundations for Climate Data

R combines statistical computing, graphics and reproducible scripting. The opening practical covers vectors, indexing, functions, data types, missing values, data frames and basic plots. These foundations matter because valid functions still produce misleading results when the object type, units, alignment or missing data rule is wrong. Inspect structure before calculating.

An object can hold a scalar, vector, table or more complex structure, and its class influences how functions interpret it. Assignment gives that object a name, while indexing selects positions or rows according to numerical, logical or named rules. Logical tests are especially powerful for climate records, but missing values can propagate through comparisons and summaries unless their treatment is deliberate.

Removing missing values from a calculation changes the denominator and should be accompanied by an observed count and coverage statement. Data import creates another boundary. Dates can arrive as text, measurement fields can contain flags, and numbers can appear plausible even when units differ. Preserve the raw field, inspect types and unique values, then create documented cleaned objects rather than overwriting evidence.

A reproducible script records the sequence from import to figure, but reproducibility alone does not make the assumptions valid. Analysts must still verify units, timestamps, spatial alignment and physical plausibility. Simple assertions can stop a workflow when lengths differ, values fall outside a credible range or required columns are absent. Clear names and intermediate objects make these checks reviewable.

The practical objective is not merely to obtain output. It is to build a traceable analysis in which another person can identify what entered each calculation, how missing observations were handled and why the resulting summary answers the engineering question.

In this chapter

What this chapter covers

  • 01

    objects and assignment in R

  • 02

    vectors and indexing

  • 03

    numeric and logical types

  • 04

    missing values

  • 05

    data frames and named columns

  • 06

    summary and plot functions

Worked example · free

Temperature vector audit

Q [5 marks]. This original practice weighting is not a University mark allocation. Temp contains 31, 34, NA, 38 and 36. Find the observed count, mean and values above 35.
R object mapScalars combine into vectors, vectors become data-frame columns, and functions produce summaries and plots.scalarvectordata framesummaryplot
The map shows how individual values form vectors, vectors become named data-frame columns, and functions turn those objects into summaries or plots.
  • 1Inspect the numeric vector.
  • 1Count four observations.
  • 1Calculate the mean as 34.75.
  • 1Return 38 and 36 safely.
  • 1Report one missing position.
There are four observed values with a mean of 34.75. The values above 35 are 38 and 36. One scheduled observation is missing and must remain visible in the report.
Sia tip — Use a missing value condition inside the subset so unknown positions do not leak into the output.
Glossary

Key terms

Vector
An ordered R object whose elements share a common type.
Data frame
A table of equal length named columns that may carry different types.
Missing value
An unavailable observation represented by NA rather than a physical zero.
FAQ

R Foundations for Climate Data FAQ

Why inspect an R object first?

Inspection reveals class, type, length, names and missingness before a function is applied. This catches imported character columns, unexpected factors and indexing mistakes that can otherwise produce plausible but invalid outputs.

When should na.rm be used?

Use it only after counting and investigating missing observations. The argument allows a summary to run but does not repair the data. Report completeness and retain the raw field so the rule remains auditable.

Why select columns by name?

Named selection states the variable being analysed and is less fragile than relying on a column position that may change after import or joins. Names should also carry enough meaning to make units and content clear.

Study strategy

Exam move

Open a fresh R script and recreate the basic object sequence without copying commands. Assign a scalar, create a numeric vector, select positions, apply a logical condition and build a data frame with named columns. After every step, use class, typeof, length or str to inspect what R actually created. Write a short comment describing the engineering meaning and unit of each object.

Repeat the temperature vector example with one missing value. Count observed positions, calculate the mean using na.rm only after the count, and subset values above the threshold with an explicit missing value condition. Print both values and indices. Explain why four observed values out of five scheduled positions is different from a complete five value record.

Import a small text or CSV file and deliberately include one nonnumeric string in a measurement column. Inspect unique values before conversion, preserve the raw field and create a cleaned numeric field with a documented rule. Count any conversion failures. This exercise trains you to treat warnings as evidence about the dataset rather than console clutter. Practise indexing with both positions and names.

Verify the first and last timestamp after every filter so an offset or reordered row cannot remain hidden behind a plausible summary. Give new objects descriptive names, including units when practical. Avoid overwriting the source column because sensitivity analysis and team review depend on the original values. Add assertions for numeric type, expected length, nonnegative flow and plausible ranges.

Trigger each assertion once with a deliberate bad input and check that the message identifies the failed variable and rule. Finish by drawing the object map from scalar to vector to data frame to summary and plot. Explain why R can validate syntax and object structure but cannot know whether two numeric columns share units or timestamps.

That final distinction is the heart of reproducible engineering analysis: computational success is necessary, while semantic checks remain the analyst's responsibility.

A+Everything unlocked
Unlocks this Bible + all 202 of your University of Sydney subjects - and 1,000+ Bibles across every Australian university.
Sia - your CIVL6001 tutor, unlimited, worked the way the exam marks it
The full 3-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works
CIVL6001 · Civil Engineering in a Changing Climate - independent study guide on the AskSia Library. More University of Sydney subjects · Microeconomics across all universities