Difficulty: beginner
Estimated Time: 10 minutes

Like many other languages, R has a variety of basic types and more complex types that can be created from the 'atomic' ones. Basic types in R are:

  • numeric (real)
  • integer
  • character
  • logical
  • complex

Because R is a dynamically typed language you are able to convert variables values from one type to the other. This scenario introduces mechanisms of conversions in R.

You've completed R Environment scenario.

You've learnt how to:

  • run the code
  • create variables
  • explore the environment
  • cleaning the environment

Find out about filtering in the next scenario of the course.

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Types conversions in R

Step 1 of 7

Implicit conversions

There are two types of conversions in R: implicit and explicit. Implicit conversions happens without specifically introducing them by the programmer and when the direct conversion from one type to the other exists.

Take a look at the following example. Let's create a vector of integers ranging form 1 to 10:

a <- 1:10 a

As you may expect the type of the vector is integer:

typeof(a)

Now let us put a value of some other type there:

a[5] <- 'some text'

You can see that the type of the whole vector has changed as implicit conversion to string typed happened:

a typeof(a)