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.
is.complex(obj)
Name | Value |
obj | It is an input R object that will be checked for data type “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
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
The is.complex() function returns FALSE for character vectors.
str <- "Willow!"
is.complex(str) # FALSE
et <- ""
is.complex(et) # FALSE
That’s all!
Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.
The scale() function in R centers (subtracting the mean) and/or scales (dividing by the standard…
To rename a file in R, you can use the file.rename() function. It renames a…
The prop.table() function in R calculates the proportion or relative frequency of values in a…
The exp() is a built-in function that calculates the exponential of its input, raising Euler's…
The split() function divides the input data into groups based on some criteria, typically specified…
The colMeans() function in R calculates the arithmetic mean of columns in a numeric matrix,…