-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy path09_How_To_Code.R
31 lines (31 loc) · 948 Bytes
/
09_How_To_Code.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#
# Author: Dr Eugene O'Loughlin
# Video Title: How To... Create a Sequence of Numbers in R
# Video Number: #09
#
# Simple sequence of 1 to 10
1:10
#
# The seq function
seq(1, 10) # simple version
seq(from = 1, to = 10) # same as above clearer syntax
seq(from = 1, to = 10, by = 2) # every second number
seq(from = 0, to = 20, by = 5)
seq(from = 1, to = 2, length.out = 5)
#
# Store sequence in a vector
mySeq <- seq(from = 1, to = 100)
print(mySeq)
#
# Some useful sequences
seq(from = 1900, to = 1999) # every year 20th century
seq(from = 1900, to = 1999, by = 10) # Each decade
seq(from = 0, to = 100) # Percent values
#
# Create a series of repeated values
rep(1, times = 5) # Replicate a number
rep(1:10, 2) # Replicate a sequence
rep(1:10, each = 2) # Replicate elements by "each" number of times
#
# Repeat text
rep("Hello", 10)