Dr. Mark Gardener


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.

Tips & Tricks for R | Tips & Tricks for Excel | An Introduction to R | MonogRaphs | Writer's Bloc



Be classy - object class attributes

All R objects have a class attribute. This can be viewed (or set) via the class() command. The class can be any character string and an object can hold more than one class. You can use the class to help you identify what sort an object is, for example:

> bird
Garden Hedgerow Parkland Pasture Woodland
Blackbird 47 10 40 2 2
Chaffinch 19 3 5 0 2
Great Tit 50 0 10 7 0
House Sparrow 46 16 8 4 0
Robin 9 3 0 0 2
Song Thrush 4 0 6 0 0

At first glance you cannot tell if this object is a data.frame or a matrix. The class() command can help you find out:

> class(bird)
[1] "matrix"

Some commands can be pressed into service for special classes – for example plot(), summary() and print() commands can be written to process objects of a specific class. You simply name your custom command to append the class; for example plot.lm(), print.lm() or summary.lm() commands, which are part of the basic distribution of R. When you issue a plot() command for example R looks at the class of the object to see if there is a plot.xxxx() command to match (where xxxx is the class of the object). If there is then this custom command is carried out. If a custom command is not available then the basic plot() command is used.

The class attribute is often used in functions to check that an object is of the right sort before carrying out the commands.

Top << Previous Tip: Add comments to objects >> Next Tip: Types of R object – 1. basics
Follow me...
Facebook Twitter Google+ Linkedin Amazon
Top Tips & Tricks Home Index of R Tips Index of Excel Tips  
More links:

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