Memra

Index prefixes, row names, truncated frames

◈ 9 cards

A long vector wraps: [1] starts the first line, [10] the second, and the prefix is the position of the first value on that line. A filtered frame keeps its original row names — 5 and 10 are identifiers, not values. A printed table() is two lines: the level names, then the counts.

Three printed shapes, one habit

The final asks you to read a value off printed R output. Three shapes cover everything in this course: a vector, a data frame, a table. Each has a piece of furniture that is not data.

Worked example — a vector that wraps

Twelve amounts fit on one line at the console's default width of 80 characters:

> orders$amount
 [1]  420  180  760  250 1320  510   90  640  305  980  215  470

The 10th value is 980 — count from [1]. Multiply by 1.13 and the values are wider, so the line wraps:

> orders$amount * 1.13
 [1]  474.60  203.40  858.80  282.50 1491.60  576.30  101.70  723.20  344.65
[10] 1107.40  242.95  531.10

The [10] at the start of the second line is the position of the first value on that line. It is not a value and not a count. So the 10th HST-inclusive amount is 1107.40 without counting anything, and the 11th is the value after it. The wrap position depends on the console width and the width of each value — in a 40-character console the same vector wraps every four values, with [5] and [9] starting the second and third lines — so never assume nine per line; read the prefix.

A filtered frame keeps its row names

> orders[orders$amount > 900, ]
   order_id prov channel amount units order_date
5      1005   AB  Online   1320     8 2025-02-03
10     1010   AB   Store    980     6 2025-03-11

Two rows passed. The 5 and 10 on the left are the row names they had in the full frame — useful, because they say which rows passed — but they are not a column. order_id is the first column; the answer to "which orders" is 1005 and 1010. nrow() of this result is 2, not 10.

A printed table is two lines

> table(orders$prov)

AB BC ON QC 
 2  3  4  3 

The first line is the level names, in level (alphabetical) order; the second is the counts. ON has 4 orders. The blank line above is where a name for the dimension would go; table(orderschannel) prints a grid with both.

head() is a preview, not a truncation

head(orders) shows six rows because six is the default, not because the frame lost rows; nrow(orders) is still 12. When a console line ends with ... — as in str() — that is display truncation, and the data underneath are complete.

Type the filter, then read three values cold

The numeric items read a value off the wrapped vector and a count off the table; the questions cover row names, the [k] prefix, and the two lines of a table.

CRISP-DM: reading output correctly is data understanding → explore data — the answer is on the screen only if the furniture is not mistaken for data.

NORMAL ~/memra/learn/afm-112/reading-printed-output utf-8 LF