Summer Deals - hours only!Up to 80% off on all courses and bundles.-Close
Strings basics
4. String length
Regular expressions
Modifying strings
Summary

Instruction

Okay, let's move on. Usually, we work with more than one string at a time, for example with a list of names. To do this, we create vectors. (You already know about vectors, right? They are simply multiple elements of the same type stored in one variable.) Let's create a vector names using c():

names <- c('John', 'Samantha', 'Paul')

We often need to check the length of each string in a vector. For example, you might need to keep strings below a certain number of characters. To check the length of each string in our vector, we will use the nchar() function. It works like this:

nchar(names)

Exercise

Display the length of the strings in the first_names vector using nchar().