Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Comments in R | Basic Syntax and Operations
R Introduction: Part I

book
Comments in R

When you've written an extensive script for research and need to revisit it later for updates or improvements, remembering the purpose of each line of code can be challenging. That’s where annotations within the code, known as comments, become invaluable.

For instance, we can add comments in two ways: as a standalone line and alongside a computation:

# Some calculation
11 + 3 # eleven plus three
12
# Some calculation 11 + 3 # eleven plus three
copy

The console will only show the result of 11 + 3 and ignore all the comments.

Comments are useful not just for clarification, but also for debugging purposes, allowing you to deactivate certain lines of code without deleting them.

Uppgift

Swipe to start coding

To make the code executable by deactivating certain lines, apply the hash # symbol to correct the errors.

Lösning

# Initial calculation
50 / 7
# Rounded number
print(50 / 7, digits = 4)

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 4
Initial calculation
50 / 7
Rounded number
print(50 / 7, digits = 4)

Fråga AI

expand
ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

some-alt