Memra

[1] is an index, not a value

◈ 8 cards

(420 + 180 + 760 + 250) / 4 prints [1] 402.5 — the [1] is the position of the first value on the line. 2^10 is 1024, 17 %% 5 is 2, and 1000000 prints as 1e+06. NA is a missing value; NULL is nothing at all.

The spreadsheet's arithmetic, without the =

The first four orders were 420, 180, 760 and 250. Their mean, in a cell, is =(420+180+760+250)/4. In the R console the same expression drops the leading =:

> (420 + 180 + 760 + 250) / 4
[1] 402.5

The precedence is the spreadsheet's: brackets, then powers, then * and /, then + and -. Without the brackets, 420 + 180 + 760 + 250 / 4 divides only the 250. The operators are the familiar ones with two additions:

> 2^10
[1] 1024
> 17 %% 5
[1] 2

^ is power, as in Sheets. %% is modulo — the remainder after division (17 = 3 × 5 + 2). It is not a percentage and not a comment.

Worked example — reading the printed line

Every result above starts with [1]. It is not part of the value. R prints a vector — a list of values — and prefixes each printed line with the index of the first element on that line. A single number is a vector of length one, so its line begins [1]. A long vector wraps, and each new line starts with the position of its first value; Lesson 9.3 shows one. Reading the mean off the console means reading 402.5, and the numeric item below is marked on exactly that.

Three more things the console prints that are not numbers:

> 1000000
[1] 1e+06
> NA
[1] NA
> NULL
NULL

1e+06 is scientific notation: 1 × 10⁶, one million. R switches to it for round numbers with many zeros (100000 prints 1e+05; 123456 prints as itself) — it is a display choice, not a change to the value, and 1e+06 + 1 is 1000001. NA is a missing value — a cell that exists but is blank, the R form of Module 2's empty cell. It sits inside a vector and takes up a position. NULL is the absence of an object altogether: no positions, length zero. A function that has nothing to return gives NULL; a missing measurement is NA.

Type two lines, then read one

Type the mean expression and the power. The numeric asks what the mean line prints — the value, not the prefix.

CRISP-DM: not a phase — this is the notation every later phase is read in.

NORMAL ~/memra/learn/afm-112/r-as-a-calculator-and-reading-the-console utf-8 LF