Skip to main content Link Search Menu Expand Document (external link)

Procedure 16: Create a logical variable by assignment

Logical variables are True or False values which are derived by logical assignment. To create a logical variable as the result of an evaluation assignment, start by creating a variable x by typing:

x <- 1

img.png

Run the line of script to console:

img_1.png

Create another variable y by typing:

y <- 2

img_2.png

Run the line of script to console:

img_3.png

The logical variable will be created as the result of comparing one variable to another, in this case, questioning if x is greater than y. Type:

Logical <- x > y

img_4.png

Run the line of script to the console:

img_5.png

It can be seen that the variable Logical has been created and is available in the Environment pane:

img_6.png

Naturally, the variable can also be referenced via simply typing into the script editor:

Logical

img_7.png

Run the script to console:

img_8.png

It can be seen that the variable has been written out as FALSE, in this instance, with the opposing value being TRUE. Using the mode() function, typing into the script editor:

mode(Logical)

img_9.png

Run the script to console:

img_10.png

It can be seen that the variable writes out as being of type logical.


Jube™. © Jube Holdings Limited 2022 to present.