Learn R Programming

proximetricsR (version 0.6.5)

locate_serialnumber_index: Function to locate the serial number index

Description

This function locates the index of a given serial number in a list of serial numbers.

Usage

locate_serialnumber_index(serial_numbers, serialnumber)

Value

The index of the serial number in the list, or the index of the closest match based on ASCII value difference.

Arguments

serial_numbers

A vector of serial numbers.

serialnumber

A single serial number to be located within the list.

Details

The function first checks if the list of serial numbers is empty and returns 1 if true. If the serial number is found in the list, it returns the last index where the serial number appears. If the serial number is not found, it calculates the ASCII value difference between the given serial number and each element in the list using the string_diff function. If all differences are larger than 256^3, it returns 1. Otherwise, it returns the index of the element with the smallest ASCII value difference.