Function that takes first n characters from (vector of) character string(s).

strHead(
        string,
        n_char=1)

Arguments

string

Character string or vector of character strings.

n_char

Number of characters to take from the head (starting at the first character) of the string (or vector of strings. Defaults to 1)

Details

Typical use of the function is return just the first few characters of a character string.

Value

Function returns a character string (vector) consisting of the first n_char of the character string (vector of character strings).

Examples

strHead(state.name, 2) ### First two characters of each state name
#> [1] "Al" "Al" "Ar" "Ar" "Ca" "Co" "Co" "De" "Fl" "Ge" "Ha" "Id" "Il" "In" "Io" #> [16] "Ka" "Ke" "Lo" "Ma" "Ma" "Ma" "Mi" "Mi" "Mi" "Mi" "Mo" "Ne" "Ne" "Ne" "Ne" #> [31] "Ne" "Ne" "No" "No" "Oh" "Ok" "Or" "Pe" "Rh" "So" "So" "Te" "Te" "Ut" "Ve" #> [46] "Vi" "Wa" "We" "Wi" "Wy"