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

Basic types of R object:


Types of R object – 1. basics

R "recognises" various sorts of object. Every object holds a class attribute, which controls how the object is dealt with by various commands.

At the most basic level you can think of R objects as being in one of three main forms:

  • numeric
  • character
  • factor

The numeric type is obvious – numbers:

> num = c(2.3, 4.1, 5, 12.2)
> num
[1] 2.3 4.1 5.0 12.2
> class(num)
[1] "numeric"

The character type is also obvious – text:

> chr = c("a", "b", "c")
> chr
[1] "a" "b" "c"
> class(chr)
[1] "character"

The last basic type is a factor. The factor can appear like a number or a character, depending upon its contents:

> fact = gl(3, 2)
> fact
[1] 1 1 2 2 3 3
Levels: 1 2 3
> class(fact)
[1] "factor"

The previous object (fact) looks like numbers. The following looks superficially like characters:

> fac = gl(3, 2, labels = c("p", "q", "r"))
> fac
[1] p p q q r r
Levels: p q r
> class(fac)
[1] "factor"

In fact you can see that it is not a character object because the text items do not have quotes around them. Another "clue" is the Levels: part of the display – but beware because this is not always displayed.

Factor objects are important and are used in many statistical analyses. When you import data using read.csv() for example, the columns of text are converted to factor objects unless you explicitly tell R otherwise.

Top << Previous Tip: Be classy - object class attributes >> Next Tip: Types of R object – 2. logical
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.

My Publications about statistics and data analysis

Managing Data Using Excel, Cover

See my personal pages at GardenersOwn

Top Home
Data Analysis
Contact GardenersOwn Homepage