R Tutorial



R COMMENTS


Comments in R

Comments are lines in your code that are ignored by the R interpreter. They are used to explain your code or leave notes for yourself or others reading the code. Comments help make your code easier to understand and maintain.

How to Write Comments

In R, a comment starts with the # symbol. Anything after # on that line is considered a comment.

# This is a comment in R
x <- 10  # Assign 10 to variable x

# Comments can be on their own line or after code
y <- 20  # Assign 20 to y
  

Why Use Comments?

  • Explain what a section of code does.
  • Make code easier to read and understand.
  • Help you remember your thought process when you revisit code later.
  • Temporarily disable code during debugging by turning it into a comment.

Example

# Calculate the area of a rectangle
length <- 5   # length of rectangle
width <- 3    # width of rectangle

area <- length * width  # multiply length and width to get area

area  # display the area
  

🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review