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

What is is.factor() Function in R

R consists of various data types, and "factor" is one of them. You can use…

19 hours ago

Efficiently Check If a Vector is Empty in R

The most efficient and idiomatic way to check if a vector is empty in R…

2 days ago

Checking If a Data Frame is Empty in R

What criteria are being evaluated to determine if a data frame is empty? There is…

3 days ago

How to Check If a List is Empty in R

What do we mean when we say an empty list? An empty list does not…

4 days ago

is.element() Function: Check Presence of Elements in R

Whether you want to do membership testing, filter data, identify missing values, check for duplicates,…

5 days ago

as.double() and is.double() Functions in R Language

Whether you want to perform calculations efficiently or derive accurate analysis, you need a double-precision…

1 week ago