PSYCH 018 Index > Introduction to R (part 2) > The Starting Number

The Starting Number

When you look at an object’s contents, R shows you the starting number of the element. Try typing the following. Press the ENTER key after you type the number 9; R will prompt you with a plus sign +, indicating “you need to type more.”

> try.me <- c(1, 2, 3, 4, 5, 6, 7, 8, 9,
+ 10, 11, 12, 13, 14, 15)

(notice that you can put a dot in the name of an object to separate words.) Now set your R console window to be really narrow, and type:

> try.me
 [1]  1  2  3  4  5  6  7  8  9 10
[11] 11 12 13 14 15

Because your output took more than one line, R split it up and told you that the first line starts with the first element [1], and the second line starts with the eleventh element [11] of the vector. Depending on the width of your window, your split point will probably be different.

Generating a Series of Numbers

If you need a series of consecutive numbers, R has a quick and easy shortcut using the colon to indicate a range of numbers. Widen your window again, and try this:

> series <- c(20:30)
> series
[1] 20 21 22 23 24 25 26 27 28 29 30

So that means you could have as easily typed:

> try.me <- c(1 : 15)

Return to Introduction part 2