Course Content
TEST R COURSE
TEST R COURSE
Converting
Good! Now you can convert numbers into integers while creating. But what if you want to convert specific results? Putting L
will not help and raise an error, like in the example below.
# Some number num <- 20 numL # Trying using L for converting
The output of the script above is:
Surely, not what we were wanted to do.
R provides us with very simple and convenient functions to convert variables/values into different formats. These are as.double()
, as.integer()
, as.complex()
. See, the functions' names are intuitive!
There is a 'hierarchy' within numerical types, i.e., each integer
number can be converted into double
and complex
, and each double
can be converted into complex
. complex
numbers can not be converted into either double
, either integer
type (unless the imaginary part is 0). double
numbers can be converted into integer
, but this will not round, but truncate to integer part.
Try these functions by yourself!
Swipe to show code editor
- Convert the number
9.85
intointeger
. - Convert the number
23.8
intocomplex
. - Convert the
integer
number42
created by usingL
intodouble
.
Thanks for your feedback!
Converting
Good! Now you can convert numbers into integers while creating. But what if you want to convert specific results? Putting L
will not help and raise an error, like in the example below.
# Some number num <- 20 numL # Trying using L for converting
The output of the script above is:
Surely, not what we were wanted to do.
R provides us with very simple and convenient functions to convert variables/values into different formats. These are as.double()
, as.integer()
, as.complex()
. See, the functions' names are intuitive!
There is a 'hierarchy' within numerical types, i.e., each integer
number can be converted into double
and complex
, and each double
can be converted into complex
. complex
numbers can not be converted into either double
, either integer
type (unless the imaginary part is 0). double
numbers can be converted into integer
, but this will not round, but truncate to integer part.
Try these functions by yourself!
Swipe to show code editor
- Convert the number
9.85
intointeger
. - Convert the number
23.8
intocomplex
. - Convert the
integer
number42
created by usingL
intodouble
.
Thanks for your feedback!
Converting
Good! Now you can convert numbers into integers while creating. But what if you want to convert specific results? Putting L
will not help and raise an error, like in the example below.
# Some number num <- 20 numL # Trying using L for converting
The output of the script above is:
Surely, not what we were wanted to do.
R provides us with very simple and convenient functions to convert variables/values into different formats. These are as.double()
, as.integer()
, as.complex()
. See, the functions' names are intuitive!
There is a 'hierarchy' within numerical types, i.e., each integer
number can be converted into double
and complex
, and each double
can be converted into complex
. complex
numbers can not be converted into either double
, either integer
type (unless the imaginary part is 0). double
numbers can be converted into integer
, but this will not round, but truncate to integer part.
Try these functions by yourself!
Swipe to show code editor
- Convert the number
9.85
intointeger
. - Convert the number
23.8
intocomplex
. - Convert the
integer
number42
created by usingL
intodouble
.
Thanks for your feedback!
Good! Now you can convert numbers into integers while creating. But what if you want to convert specific results? Putting L
will not help and raise an error, like in the example below.
# Some number num <- 20 numL # Trying using L for converting
The output of the script above is:
Surely, not what we were wanted to do.
R provides us with very simple and convenient functions to convert variables/values into different formats. These are as.double()
, as.integer()
, as.complex()
. See, the functions' names are intuitive!
There is a 'hierarchy' within numerical types, i.e., each integer
number can be converted into double
and complex
, and each double
can be converted into complex
. complex
numbers can not be converted into either double
, either integer
type (unless the imaginary part is 0). double
numbers can be converted into integer
, but this will not round, but truncate to integer part.
Try these functions by yourself!
Swipe to show code editor
- Convert the number
9.85
intointeger
. - Convert the number
23.8
intocomplex
. - Convert the
integer
number42
created by usingL
intodouble
.