Learn R Programming

dissimilarities (version 0.3.0)

get1dFrom2d: 2D-indexing to 1D-indexing

Description

Efficiently computes 1D-indexing from 2D-indexing

Usage

get1dFrom2d(i,j, N)

Value

An integer specifying the 1d index

Arguments

i

An integer specifying the row index

j

An integer specifying the column index - must be different from i as "dist" object does not store the diagonal entries.

N

The number of observations in the original data matrix

Author

Minh Long Nguyen edelweiss611428@gmail.com

Details

Converts 2D indexing (a row-column pair) into 1D indexing (as used in R's "dist" objects), given the number of observations N.

Currently, name-based indexing is not supported."

Examples

Run this code
N = 5
for(i in 1:4){
  for(j in (i+1):5){
    print(get1dFrom2d(i,j,N))
  }
}

Run the code above in your browser using DataLab