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 

Naming matrix rows & columns: 
Naming rows and columns of a matrixYou make a matrix using matrix() rbind() or cbind() commands. The names of the rows and columns can be set after the matrix is produced in various ways:
The rownames() and colnames() commands set the row and column names respectively: > m1 = matrix(1:12, nrow = 3) The commands can also query the names: > rownames(m1) Note that the basic names() command does not work for matrix objects: > names(m1) If you use the rbind() command then the rows will be named according to the data names that you use unless you specify otherwise: > d1 = 1:4 ; d2 = 5:8 ; d3 = 9:12 Similarly with the cbind() command the columns take the names of the objects unless you specify them explicitly. You can set the row and column names in one go using the dimnames() command. This requires a list() of two items (the row names and the column names): > m1 If you use the matrix() command you can incorporate the dimnames() command within it to set the names: > m3 < matrix(1:12, nrow = 3, dimnames = list(month.abb[1:3], month.abb[4:7])) > m3 Of course you can also use the dimnames() command to view the current names – more on this another time. 

<< Previous Tip: Make a matrix  >> Next Tip: Row & column names using dimnames()  
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 