Search⌘ K
AI Features

Solution Review: Variables

Explore how to determine the data types of variables in R by using class() to find high-level types and typeof() for underlying types. This lesson guides you through printing these details with cat() to understand R variables and their basic operations.

Solution: Use class() and typeof()

R
testVariable <- 1.9
# getting high level data type with class() and low level data type with typeof
cat(class(testVariable), typeof(testVariable))

Explanation

The first task we were given was to find the high-level data type of the given testVariable. We can do this by using the class() function with the given testVariable. The second task was to print the low-level data type of the testVariable and for that, we use the typeof() function with the testVariable.

A function is a set of instructions that perform a task. We will learn more about functions later in the course.

We pass both these functions to cat() for printing.