R Basic

What is is.complex() function in R

If you are working with imaginary components, you might want to find whether you are working with complex numbers or not and that’s where the is.complex() function helps you.

The is.complex() is a built-in R function that checks whether an input object is of type “complex”. It returns TRUE if it is complex and FALSE if not.

Syntax

is.complex(obj)

Parameters

Name Value
obj It is an input R object that will be checked for data type “complex”.

Visual Representation

Check if an input object is complex

R does not implicitly convert any number to a complex number; you have to create a complex number using the complex() function and pass the “real” and “imaginary” arguments.

is.complex(1 + 9i) # TRUE
is.complex(21) # FALSE
is.complex(2 - 1i) # TRUE

data <- complex(real = 1, imaginary = 2)
is.complex(data) # TRUE

Logical values

The is.complex() function returns FALSE for logical (TRUE or FALSE) values.

bool_val <- TRUE
is.complex(bool_val) # FALSE

bool_value <- FALSE
is.complex(bool_value) # FALSE

Character strings

The is.complex() function returns FALSE for character vectors.

str <- "Willow!"

is.complex(str) # FALSE

et <- ""

is.complex(et) # FALSE

That’s all!

Recent Posts

R length(): Vector, List, Matrix, Array, Data Frame, String

Before executing an operation on an object, it is advisable to check its length, as…

1 day ago

How to Round Numbers in R

Rounding is a process of approximating a number to a shorter, simpler, and more interpretable…

2 days ago

Adding Single or Multiple Columns to Data Frame in R

Whether you want to add new data to your existing datasets or create new variables…

4 days ago

sqrt() Function: Calculate Square Root in R

The square root of a number is a value that is multiplied by itself, giving…

5 days ago

How to Remove Duplicate Rows from DataFrame in R

Duplicate rows refer to all the values across all columns that are the same in…

7 days ago

How to Remove NA From Vector in R

A vector is a data structure that holds the same type of data. When working…

1 week ago