Winston
Winston

Reputation: 641

2d-list with 2-tuples as indexes

I'm pretty new to R, is there a way to have a two-dimensional list of two-tuples as indexes in R programming language?

For example :

my_list[(1,2)] 
#[1] 7, 10, 3

Upvotes: 0

Views: 289

Answers (1)

yassem
yassem

Reputation: 61

Sorry, I cannot comment yet but it kind of sounds like you just mean a matrix.

Please write what exactly you want to achieve. In case you actually mean matrices it work like this:

You can define a matrix, e.g. a 3x3 matrix of numbers 1:9:

A = matrix(1:9, nrow=3, ncol=3)

Then reference the i-th row and j-th column by A[i, j].

A[1, 3]
[1] 7

You can have any number of dimensions using array.

Hope that helps

Upvotes: 1

Related Questions