Normal languages like Java and Python let you make arrays of arrays and lists of lists. Composition is one of the great ideas of computer science.

, on the other hand, has special names and syntax for each level.

All same type? One dimension is a vector, two is a matrix, three is an array.

> 1:3
[1] 1 2 3
> matrix(1:9, nrow=3)
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
> array(1:27, dim=c(3, 3, 3))
, , 1

[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9

, , 2

[,1] [,2] [,3]
[1,] 10 13 16
[2,] 11 14 17
[3,] 12 15 18

, , 3

[,1] [,2] [,3]
[1,] 19 22 25
[2,] 20 23 26
[3,] 21 24 27

Lists allow for different types within the same structure (although I don't use them in the example below). The display syntax does not scream consistency or concision:

> a = list(x=1, y=2)
> a
$x
[1] 1

$y
[1] 2

> list(a, a)
[[1]]
[[1]]$x
[1] 1

[[1]]$y
[1] 2

[[2]]
[[2]]$x
[1] 1

[[2]]$y
[1] 2

> list(list(a, a), list(a, a))
[[1]]
[[1]][[1]]
[[1]][[1]]$x
[1] 1

[[1]][[1]]$y
[1] 2

[[1]][[2]]
[[1]][[2]]$x
[1] 1

[[1]][[2]]$y
[1] 2

[[2]]
[[2]][[1]]
[[2]][[1]]$x
[1] 1

[[2]][[1]]$y
[1] 2

[[2]][[2]]
[[2]][[2]]$x
[1] 1

[[2]][[2]]$y
[1] 2

(Yes, that last monstrosity is a display of a three dimensional list containing *eight numbers*.)

It's like reading old math texts, where statements are in paragraphs instead of symbols and there is special terminology for rhombuses and surjections and "summing to unity". How about we just cut to the chase and use Roman numerals?

@data_science

Follow

@data_science

Of course those are built into the base language.

> as.roman(13)
[1] XIII

· · 1 · 1 · 2

@peterdrake @data_science What in the world??? I didn't know this. Also, is this used in some sort of Latex connection in R? I've used Latex through R and it seems that is a relevant house for this function.

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.