BIOL2001 Chap.1 Values, Data Types and Data Structures in R
Values, Data Types and Data Structures in R
The first week of R
Part I opens with how an R session works: you type a command at the prompt, R reads it, evaluates it and prints the result.
The chapter covers the arithmetic operators, including integer division and modulo, the logical operators that return TRUE or FALSE, and the assignment arrow that stores a value under a name.
Types and structures
Every value has a type: integer, double, logical or character, checked with typeof(). Missing and impossible values have their own markers, NA, Inf, NaN and NULL.
Values are then organised into structures.
R has no scalars, so the simplest structure is the vector, and the chapter places vectors, matrices, lists and data frames on a map defined by two questions: do the elements share one type, and are there one or two dimensions?
Why it matters later
Every later chapter, from indexing to regression output, assumes you can tell a vector from a list and a double from a character string at a glance.
What this chapter covers
- 01
The read-evaluate-print loop and RStudio
- 02
Arithmetic operators including %/% and %%
- 03
Logical operators and TRUE or FALSE results
- 04
Assignment with the arrow operator
- 05
Integer, double, logical and character types
- 06
NA, Inf, NaN and NULL
- 07
Atomic vectors and why R has no scalars
- 08
Matrices, lists and data frames compared
Worked example · free
Placing four objects on the structure map
- 1The pond counts share one type and run in one dimension, so they form an atomic vector, for example c(4, 0, 7).
- 1The numbers 1 to 12 in rows and columns share one type in two dimensions: a matrix, matrix(1:12, nrow = 3).
- 1The record mixes text, a logical and a number in one dimension, so it must be a list.
- 1The field sheet has two dimensions with a different type in each column: a data frame.
Key terms
- Atomic Vector
- A one-dimensional R structure whose elements all share a single type.
- Data Type
- The kind of value stored, such as integer, double, logical or character.
- Modulo Operator
- The operator %% that returns the remainder after dividing one number by another.
- Missing Value
- The marker NA, which holds the place of an unknown value in any type of vector.
- Integrated Development Environment
- Software such as RStudio that combines a console, a script editor, plots and help in one window.
Values, Data Types and Data Structures in R FAQ
What is the difference between a data type and a data structure in R?
A data type describes a single piece of data, such as integer, double, logical or character. A data structure describes how pieces are organised, such as a vector, matrix, list or data frame. A vector of integers has vector as its structure and integer as its type.
Why does typeof(10) return double rather than integer?
R stores a plain number such as 10 as a floating-point double by default. To store it as an integer you add the L suffix, writing 10L, and typeof(10L) then returns integer. The difference rarely changes a calculation but explains the output you see.
What is the difference between NA, NaN and NULL?
NA marks a value that is missing but exists, NaN is the result of a calculation with no sense such as 0 divided by 0, and NULL is an empty object with no value at all. NA has type logical on its own, NaN is a double and NULL has its own type.
Is R case sensitive?
Yes. Assigning a value to x and then another to X creates two separate variables, and calling a function with the wrong capitalisation fails. Consistent lower-case names avoid a common source of errors in timed coding tasks.
Assessment move
Open RStudio beside this chapter and run every operator in the table, then predict the output of typeof() for ten values of your own before checking. Build one example of each structure from a dataset you know, such as counts from a field trip, and say aloud why it is that structure. Finish by creating a vector containing NA and checking it with is.na().
A good self-test is to explain, without running anything, why typeof(NA) is logical while typeof(NaN) is double, and why a vector of length one is how R stores what other languages call a scalar.
Working through Values, Data Types and Data Structures in R in BIOL2001? Sia is AskSia’s AI Statistics tutor — ask any BIOL2001 Values, Data Types and Data Structures in R question and get a clear, step-by-step explanation grounded in how BIOL2001 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.
STAT1008 Quantitative Research Methods · BIOL1030 Diversity of Life · STAT7038 Regression Modelling