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

colSums(): Calculating the Sum of Columns of a Data Frame in R

The colSums() function in R calculates the sums of columns for numeric matrices, data frames,…

4 days ago

rowSums(): Calculating the Sum of Rows of a Matrix or Data Frame in R

The rowSums() function calculates the sum of values in each numeric row of a matrix,…

1 week ago

R View() Function

The View() is a utility function in R that invokes a more intuitive spreadsheet-style data…

2 weeks ago

summary() Function: Producing Summary Statistics in R

The summary() is a generic function that produces the summary statistics for various R objects,…

3 weeks ago

R paste() Function

The paste() function in R concatenates vectors after converting them to character. paste("Hello", 19, 21,…

4 weeks ago

paste0() Function in R

R paste0() function concatenates strings without any separator between them. It is a shorthand version…

4 weeks ago