Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære print() Function | Syntax and Basic Operations
R Introduction

bookprint() Function

When R displays results, the output is often preceded by [1]. This marker indicates that the line begins with the first element of the result. For larger outputs, you will see additional markers such as [2], [3], and so on.

Using print()

Although R automatically shows results, you can use the print() function to control how output is displayed. One of its options is the digits argument, which rounds numbers to a chosen number of significant figures.

print(expression, digits = n)

Example

12
5 / 3 print(5 / 3, digits = 3)
copy

Here, the output of print() is rounded to three significant figures, making results easier to read.

Oppgave

Swipe to start coding

  1. On the first line, execute a division of 50 by 7.
  2. On the second line, divide 50 by 7 again, but this time round the result to four significant figures using the print() function.

Løsning

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 3
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Suggested prompts:

What other arguments can I use with the `print()` function in R?

Can you explain more about how the `digits` argument works?

Why does R automatically display results without using `print()`?

close

Awesome!

Completion rate improved to 2.27

bookprint() Function

Sveip for å vise menyen

When R displays results, the output is often preceded by [1]. This marker indicates that the line begins with the first element of the result. For larger outputs, you will see additional markers such as [2], [3], and so on.

Using print()

Although R automatically shows results, you can use the print() function to control how output is displayed. One of its options is the digits argument, which rounds numbers to a chosen number of significant figures.

print(expression, digits = n)

Example

12
5 / 3 print(5 / 3, digits = 3)
copy

Here, the output of print() is rounded to three significant figures, making results easier to read.

Oppgave

Swipe to start coding

  1. On the first line, execute a division of 50 by 7.
  2. On the second line, divide 50 by 7 again, but this time round the result to four significant figures using the print() function.

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

close

Awesome!

Completion rate improved to 2.27
Seksjon 1. Kapittel 3
single

single

some-alt