Learn R Programming

blockmodeling (version 1.1.8)

encodeToZeroIndexed: Encode Integer Vector with Consecutive Values Starting from 0

Description

This function maps an integer vector to a new vector where the unique values are replaced with consecutive integers starting from 0.

Usage

encodeToZeroIndexed(x)

Value

An integer vector with values from 0 to (number of unique values - 1), maintaining the original order structure.

Arguments

x

An integer vector.

Examples

Run this code
encodeToZeroIndexed(c(10, 20, 10, 30))
# Returns: 0 1 0 2

Run the code above in your browser using DataLab