Let’s start by creating some data.
One way we can do this is using the sequence function
The function is seq() and the arguments are seq(beginning, end, increment)
for example:
Input:
x <- seq(1,5,1)
print(x)
Output:
[1] 1 2 3 4 5
If we want to create a repeated values we can use the rep()
function
The arguments are rep(what to replicate, how many times)
This can be done for all variable types. In the examples below we replicate an integer and a string
Input:
y <- rep(3,5)
print(y)
Output:
[1] 3 3 3 3 3
Input:
z <- rep('True',5)
print(z)
Output:
[1] "True" "True" "True" "True" "True"