Skip to content

Instantly share code, notes, and snippets.

@LetticiaNicoli
Last active May 8, 2019 23:36
Show Gist options
  • Save LetticiaNicoli/fe1714ba6504b4b4a237016e68e22a15 to your computer and use it in GitHub Desktop.
Save LetticiaNicoli/fe1714ba6504b4b4a237016e68e22a15 to your computer and use it in GitHub Desktop.
Sequency and Replication in R
#Sequency
#For simple tests (don't use in prod)
1:9
80:32
4:-2
3:3
1:0
#Seq Function
seq(0, 1, length.out = 11)
seq(stats::rnorm(20))
seq(1, 9, by = 2)
seq(1, 9, by = pi) # stays below 'end'
seq(1, 6, by = 3)
seq(1.575, 5.125, by = 0.05)
seq(17) # same as 1:17, or even better
seq_len(17)
#Replication
rep(0, times = 40)
rep(c(0, 1, 2), times = 10)
rep(c(0, 1, 2), each = 10)
#Create seq
my_seq = seq(5, 10, length.out = 30)
my_seq2 = seq(from = 5, by = 10, length = 30)
#Length Seq
length(my_seq2)
#Set seq with variable
my_seq_clone = seq_along(my_seq2)
#or
seq(along.with=my_seq)
#Help Operator
?':'
#or
?`:`
#Random Examples
pi:10
10:pi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment