Sequences of Numbers in R

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/15

flashcard set

Earn XP

Description and Tags

3rd lesson in 1 basics of R

16 Terms

1
New cards

What happens if I code > 1:20

It will give you all the integers in between 1 and 20 in increments of 1 e.g. [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

2
New cards

What happens if I code > 15:1

It counted backwards in increments of 1 from 15 to 1 e.g. [1] 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

3
New cards

what do i do if i want to ask about the : colon function using R’s function ?

?`:`

use backticks in between the colon

4
New cards

how is another way that I can list numbers from 1 to 20 without using the : colon function?

use the seq() function e.g. seq(1,20)

5
New cards

let's say that instead we want a vector of numbers ranging from 0 to 10, incremented by 0.5.

seq(0, 10, by=0.5)

6
New cards

we don't care what the increment is and we just want a sequence of 30 numbers between 5 and 10.

seq(5, 10, length=30)

7
New cards

I want to find the length of my sequence, which I have stored in a variable called my_seq, how do i do that?

length(my_seq)

8
New cards

I want to generate a sequence from 1 to however long the sequence is in the variable my_seq so, from 1 to N so for example if my_seq has a sequence of 5, i want to generate a sequence 1 through 5, but i dont know how long the sequence is in my_seq

seq_along(my_seq) (result: 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)

9
New cards

I am interested in creating a vector that contains 40 zeros, how do i do this? HINT:REPEAT

rep(0, times=40) (result = [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)

10
New cards

instead we want our vector to contain 10 repetitions of the vector (0, 1, 2)

rep(c(0,1,2), times=10) *NOTE: Dont forget the c() it tells R that 0,1,2 is a vector

11
New cards

let's say that rather than repeating the vector (0, 1, 2) over and over again, we want our vector to contain 10 zeros, then 10 ones, then 10 twos

rep(c(0, 1, 2), each=10) (RESULT: [1] 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2)

12
New cards
13
New cards
14
New cards
15
New cards
16
New cards