Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Type Conversion | Section
Essential R Programming for Absolute Beginners - 1768563985826

bookType Conversion

Numbers can be converted between different types using built-in functions. This allows you to work with values as integers, doubles, or complex numbers when needed.

Incorrect Conversion

Simply appending L to an existing variable does not convert it:

12
num <- 20 numL # Invalid way to convert
copy

Correct Conversion

Instead, you should use one of these functions:

  • as.integer();
  • as.double();
  • as.complex().
123
as.integer(3.8) as.double(5L) as.complex(7)
copy

Numerical types follow a hierarchy, which defines how values can be converted:

  • integer → double → complex conversions are always valid;
  • Converting a double into an integer truncates the decimal part;
  • A complex number can be converted only if its imaginary part is zero.
Taak

Swipe to start coding

  1. Convert the number 9.85 to an integer.
  2. Convert the integer 42, created with L, to a double.

Oplossing

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 13
single

single

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

close

bookType Conversion

Veeg om het menu te tonen

Numbers can be converted between different types using built-in functions. This allows you to work with values as integers, doubles, or complex numbers when needed.

Incorrect Conversion

Simply appending L to an existing variable does not convert it:

12
num <- 20 numL # Invalid way to convert
copy

Correct Conversion

Instead, you should use one of these functions:

  • as.integer();
  • as.double();
  • as.complex().
123
as.integer(3.8) as.double(5L) as.complex(7)
copy

Numerical types follow a hierarchy, which defines how values can be converted:

  • integer → double → complex conversions are always valid;
  • Converting a double into an integer truncates the decimal part;
  • A complex number can be converted only if its imaginary part is zero.
Taak

Swipe to start coding

  1. Convert the number 9.85 to an integer.
  2. Convert the integer 42, created with L, to a double.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 13
single

single

some-alt