Using the print() Function
After running the code in the previous chapter, you may have noticed [1]
preceding the results. This is R's way of indicating that the line starts with the first element in your output. As you progress through the course, you'll encounter outputs with multiple elements.
Let's say we want to carry out a division operation:
15/3
As we already know, in R, it's unnecessary to use a specific function to display output values. However, if your goal is to round a number to a desired number of significant figures, you can use the print()
function, which you may also recognize from other programming languages.
Here's how you use the function:
print(expression, digits = n)
For instance, we can round the division result from our previous example to three significant figures:
1print(5/3, digits = 3)
As demonstrated, the output of the expression has been rounded to three significant figures.
Swipe to start coding
- On the first line, execute a division of
50
by7
. - On the second line, divide
50
by7
again, but this time round the result to four significant figures using theprint()
function.
Soluzione
Grazie per i tuoi commenti!
single
Chieda ad AI
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione
Awesome!
Completion rate improved to 3.85
Using the print() Function
Scorri per mostrare il menu
After running the code in the previous chapter, you may have noticed [1]
preceding the results. This is R's way of indicating that the line starts with the first element in your output. As you progress through the course, you'll encounter outputs with multiple elements.
Let's say we want to carry out a division operation:
15/3
As we already know, in R, it's unnecessary to use a specific function to display output values. However, if your goal is to round a number to a desired number of significant figures, you can use the print()
function, which you may also recognize from other programming languages.
Here's how you use the function:
print(expression, digits = n)
For instance, we can round the division result from our previous example to three significant figures:
1print(5/3, digits = 3)
As demonstrated, the output of the expression has been rounded to three significant figures.
Swipe to start coding
- On the first line, execute a division of
50
by7
. - On the second line, divide
50
by7
again, but this time round the result to four significant figures using theprint()
function.
Soluzione
Grazie per i tuoi commenti!
Awesome!
Completion rate improved to 3.85single