Great job! Now, let's take a look a short piece of a code that uses several of the functions we've learned:
#These functions take text values as arguments
#substr returns first 8 characters from string
first_eight <- substr("comments are useful", 1, 8)
#nchar takes a string and returns a number
name <- "Mary"
name_num_letters <- nchar(name)
You probably noticed that several lines in the block of code above start with the
. These are
in R. Anything that follows a
on one line is considered a comment.
When R sees
#, it simply skips the rest of the line and moves on to the next one. Nothing happens when you write a comment in your code. These are just used for the purpose of documentation or clarification.