My homework asks me to create a sequence like this.
(1, 2, 2, 3, 4, 4, 5, 6, 6, . . . , 50, 50)
I'm a newbie to R so would really appreciate your help
CodePudding user response:
You can use rep and alternate the number of repeats. Check ?rep for more information.
rep(1:50, ifelse(seq(1:50) %% 2, 1, 2))
Or, with two reps:
rep(1:50, rep(1:2, 25))
rep(1:50, rep(1:2, length.out = 50))
CodePudding user response:
Short code using integer division:
2:76%/%1.5
This will return a numeric vector.
