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

Multidimensional objects:



Multi-dimensional objects in R

A vector is a one-dimensional object in R. Usually the vector looks like a row but it really acts like a column. When you make more complicated objects you add more dimensions, commonly used multi-dimensional objects are:

  • matrix
  • data.frame
  • table
  • array
  • list

A matrix is a 2-dimensional object with rows and columns. A data.frame is also 2-dimensional with rows and columns. A table can have more than 2 dimensions – a three-dimensional table would appear as several two-dimensional tables. An array is similar to a table (the difference is largely how you build it to start with). A list is the most "primitive" of the objects and is a loose collection of other objects, bundled together.

A matrix contains rows and columns but all the data in the matrix must be of the same type, that is, all numbers or all text. You can think of a matrix as a single vector that happens to be split up into rows and columns. In fact, one way to make a matrix is to do just that:

> matrix(1:12, ncol = 4)

[,1] [,2] [,3] [,4]
[1,] 1 4 7 10
[2,] 2 5 8 11
[3,] 3 6 9 12

A data.frame also contains rows and columns but the columns can be of different types, so you can have one column that is numeric, one that is character and one that is a factor.

> a = 1:4

> b = c("one", "two", "three", "four")

> c = gl(2,2,labels = c("high", "low"))

> data.frame(b, a, c)
b a c
1 one 1 high
2 two 2 high
3 three 3 low
4 four 4 low

You can use the class() command to tell you what kind of object you are dealing with.

Top << Previous Tip: Vector objects >> Next Tip: Make a matrix
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