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 

Vector Objects 
Vector ObjectsA vector is a onedimensional object in R. There is no class specific for a vector but a vector object can be one of several classes, most usually:
Your numeric vector can be given as double or integer. Note that a factor is not considered to be a vector. You can make a blank vector using the vector() command: > vector(mode = "logical", length = 0) For example: > vl = vector(mode = "logical", length = 3) > vi = vector(mode = "complex", length = 3) The blank vector you create can be "filled in" later: > vi[1] = 3+2i Notice though that the value you enter can either be coerced to the appropriate form or alter the class of the vector: > vc[1] = 23 The value entered was a number (23) but the vector it is added to remains character in class. In the next example you create an integer vector: > vi = vector(mode = "integer", length = 3) Adding a value can alter the class: > vi[1] = 2 In this case the value (2) is taken as a regular double precision numeric value. To force the value to remain an integer you need to use the as.integer() command: > vi = vector(mode = "integer", length = 3) Now the entered value keeps its integer class. 

Top  << Previous Tip: Types of R object – 3. complex numbers  >> Next Tip: Multidimensional objects in R  
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. 


Top  Home  Contact  GardenersOwn Homepage 