Dr. Mark Gardener 


Home  
Providing training for:

Tips and Tricks  for R and ExcelOn 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 mindboggling 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 

Make a matrix: 
Make a matrixA matrix is a 2D object with rows and columns that contains data all of the same sort, e.g. all numbers or all text. You can make a matrix in various ways:
The matrix() command assumes that the vector of data will split "nicely" into rows and columns; if it doesn't then you may have to add NA items at the end to make it factorise. > dat = 1:12 The vector is split columnwise unless you specify that you want to fill rowwise using the byrow = TRUE instruction. The rbind() and cbind() commands join items as rows or columns: > d1 = 1:4 ; d2 = 5:8 ; d3 = 9:12 The rows or columns have names taken from the original vector names. You can also use the commands to add rows or columns to an existing matrix, as long as the dimensions are appropriate: > mat = cbind(d1, d2, d3) You can alter the names of the rows and columns afterwards. 

Top  << Previous Tip: Multidimensional objects in R  >> Next Tip: Naming rows and columns of a matrix  
Follow me... 

Top  Tips & Tricks Home  Index of R Tips  Index of Excel Tips  
More links: 
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 See my personal pages at GardenersOwn 

Top  Home  Contact  GardenersOwn Homepage 