1.7) Some Basic Functions
c() |
This, probably the most common R function, means ‘concatenate’. It creates simple vectors by stringing together as many elements (numbers or characters) as you give it, separated by commas: e.g. Abundance <- c("D","A","F","A") . |
: |
The colon can be used to generate sequences of integers. So -1:2 gives the same thing as c(-1,0,1,2) . |
Create a vector called t
consisting of the numbers 0, 1 and 2, and a vector called x
containing the numbers 1 to 100 (use the colon :
to create a sequence). See what happens if you add two vectors of different lengths: x + t
.
This shows two things: (i) R is quite good at making sense out of anything you type (and only sometimes gives error messages or warnings); and (ii) the importance of checking what’s going on regularly.
The “recycling rule” means that the shorter vector is reused, element-by-element, until the length of the longer one is reached.