A complex type in R is a data type used to store numbers with both real and imaginary parts, like 3 + 2i.
Click to reveal answer
beginner
How do you create a complex number in R?
You can create a complex number by using the syntax: complex(real = 3, imaginary = 2) or simply by writing 3 + 2i.
Click to reveal answer
beginner
What function returns the imaginary part of a complex number in R?
The function Im() returns the imaginary part of a complex number.
Click to reveal answer
intermediate
What does the Mod() function do with a complex number in R?
The Mod() function returns the modulus (or absolute value) of a complex number, which is the distance from zero in the complex plane.
Click to reveal answer
beginner
How can you add two complex numbers in R?
You add two complex numbers just like regular numbers using the + operator, for example: (3 + 2i) + (1 + 4i).
Click to reveal answer
Which of the following is a valid complex number in R?
A5 + 3
B5 + 3j
C5i + 3
D5 + 3i
✗ Incorrect
In R, complex numbers use 'i' for the imaginary part, so '5 + 3i' is correct.
What does the function Re() return when used on a complex number?
AImaginary part
BArgument
CReal part
DModulus
✗ Incorrect
Re() returns the real part of a complex number.
How do you find the argument (angle) of a complex number in R?
AUsing <code>Arg()</code>
BUsing <code>Mod()</code>
CUsing <code>Im()</code>
DUsing <code>Re()</code>
✗ Incorrect
Arg() returns the argument (angle) of a complex number.
What is the output of Mod(3 + 4i) in R?
A5
B7
C1
D12
✗ Incorrect
The modulus is sqrt(3^2 + 4^2) = 5.
Which function creates a complex number from real and imaginary parts in R?
AmakeComplex()
Bcomplex()
Ccomplexify()
DcreateComplex()
✗ Incorrect
The complex() function creates complex numbers from real and imaginary parts.
Explain how to create and use complex numbers in R with examples.
Think about how you write complex numbers and how to get their parts.
You got /4 concepts.
Describe the functions used to get the modulus and argument of a complex number in R and why they are useful.
Consider the complex number as a point on a plane.
You got /4 concepts.
Practice
(1/5)
1. What does the complex type in R represent?
easy
A. Only integers
B. Only real numbers without decimals
C. A number with both real and imaginary parts
D. Text strings representing numbers
Solution
Step 1: Understand the complex type definition
The complex type stores numbers that have two parts: a real part and an imaginary part.
Step 2: Compare with other number types
Unlike integers or real numbers, complex numbers include an imaginary component, often written with 'i'.
Final Answer:
A number with both real and imaginary parts -> Option C
Quick Check:
Complex type = real + imaginary parts [OK]
Hint: Complex numbers always have real and imaginary parts [OK]
Common Mistakes:
Thinking complex numbers are only real numbers
Confusing complex with integer or character types
Ignoring the imaginary part
2. Which of the following is the correct way to create a complex number in R?
easy
A. complex(real = 3, imag = 4)
B. complex(3 + 4)
C. complex(3, 4i)
D. complex(real = 3, imaginary = 4)
Solution
Step 1: Recall the correct argument names for complex()
In R, the function complex() uses 'real' and 'imag' as argument names for the parts.
Step 2: Check each option's syntax
complex(real = 3, imag = 4) is correct. complex(real = 3, imaginary = 4) is invalid because 'imaginary' is not a recognized argument. complex(3, 4i) mixes numeric and complex literal incorrectly. complex(3 + 4) is incomplete and invalid.
Final Answer:
complex(real = 3, imag = 4) -> Option A
Quick Check:
Use 'imag' not 'imaginary' in complex() [OK]
Hint: Use 'imag' for imaginary part in complex() [OK]
Common Mistakes:
Using 'imaginary' instead of 'imag' argument
Trying to mix numeric and complex literals incorrectly
Omitting closing parentheses
3. What is the output of the following R code?
z <- 3 + 4i
Mod(z)
medium
A. 5
B. 7
C. 12
D. 25
Solution
Step 1: Understand Mod() function
Mod(z) returns the modulus (length) of the complex number z, calculated as sqrt(real^2 + imaginary^2).
Adding real and imaginary parts instead of squaring
Confusing Mod() with Arg()
Calculating 3 + 4 instead of sqrt(3² + 4²)
4. Identify the error in this R code snippet:
z <- complex(real=2, imag=3)
Re(z)
medium
A. The argument 'imag' should be 'imaginary'
B. Re() cannot be used on complex numbers
C. Missing parentheses in Re(z)
D. complex() does not accept named arguments
Solution
Step 1: Check argument names in complex()
The argument 'imag' is correct for the imaginary part in complex().
Step 2: Verify usage of Re()
Re() correctly extracts the real part from a complex number, so its usage is correct.
Final Answer:
Re() cannot be used on complex numbers -> Option B
Quick Check:
Re() is valid for complex numbers, so no error here [Incorrect]
Hint: Use 'imag' for imaginary part, not 'imaginary' [OK]
Common Mistakes:
Using 'imag' instead of 'imaginary'
Thinking Re() is invalid for complex numbers
Forgetting to close parentheses
5. Given a vector of complex numbers z <- c(1+1i, 2+2i, 3+3i), which R code correctly creates a named list with keys as the real parts and values as the imaginary parts?
Step 2: Create named list with real parts as names and imaginary parts as values
setNames() assigns names to list elements. as.character(Re(z)) converts real parts to strings for names. as.list(Im(z)) converts imaginary parts to list values.
Final Answer:
setNames(as.list(Im(z)), as.character(Re(z))) -> Option D
Quick Check:
Names = real parts, values = imaginary parts [OK]
Hint: Use setNames() with real parts as names, imaginary as values [OK]
Common Mistakes:
Swapping real and imaginary parts
Not converting real parts to character for names
Using list() without names
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.