Dr. Mark Gardener

Home

Providing training for:

• Ecology
• Data analysis
• Statistics
• R The statistical programming language
• Data management
• Data mining

# Tips and Tricks - for R and Excel

On this page you can find tips, tricks and hints for using both R and Excel. At the end of each tip there are links forwards and backwards as appropriate. There is also an index of R tips and an index of Excel tips.

For most analytical purposes the combination of Excel and R is unbeatable! Excel is great as a data management tool and for preparing data for analysis. You can also use it to get an overview of your data or to make simple (and not so simple) graphs. R is an analytical "swiss army knife" and can carry out a mind-boggling array of analytical routines as well as producing great graphics.

Object class complex
Re()
Im()
Mod()
Arg()
Conj()

Top

### Types of R object – 3. complex numbers

All R objects have a class attribute, which can be important as R "decides" how to deal with objects based upon their class.

You can think of the simple classes as being in different categories:

• Basic: numeric, character or factor
• Logical: TRUE or FALSE
• Complex: A number with real and imaginary parts

You can make a complex number simply by appending an "imaginary" part to an actual number:

> newvec = c(1+1i, 2+3i)
> newvec
[1] 1+1i 2+3i

So, R recognises 2+3i for example as a complex number with real part = 2, imaginary part = 3

The class() command shows that the result is complex:

> class(newvec)
[1] "complex"

There are several commands associated with complex numbers:

> Re(newvec) # The real part of the number
[1] 1 2

> Im(newvec) # The imaginary part
[1] 1 3

> Mod(newvec) # The modulus
[1] 1.414214 3.605551

> Arg(newvec) # The argument
[1] 0.7853982 0.9827937

> Conj(newvec) # The complex conjugate
[1] 1-1i 2-3i

The commands help in dealing with complex numbers. In addition, the elementary trigonometric, logarithmic, exponential, square root and hyperbolic functions are implemented for complex values.

Top << Previous Tip: Types of R object – 2. logical >> Next Tip: Vector objects

Top Tips & Tricks Home Index of R Tips Index of Excel Tips

An introduction to R

See my Publications about Excel, R, statistics and data analysis Courses in R, data analysis, data management and statistics Visit the R Project website

See my Publications about statistics and data analysis.

MonogRaphs: random topics in R

Writer's Bloc – my latest writing project includes R scripts

Courses in data analysis, data management and statistics.

Top Home
Data Analysis
Contact GardenersOwn Homepage