Below are the solutions to these exercises on regular sequences.
#################### # # # Exercise 1 # # # #################### #if x <- c(a = 1, b = 2,c=3,d=4) #What is the output for the code: seq(5,11,along.with =x)
## [1] 5 7 9 11
#################### # # # Exercise 2 # # # #################### #If x= seq(4,12,4) #what is the output for the code: rep(x,each=2)
## [1] 4 4 8 8 12 12
#################### # # # Exercise 3 # # # #################### #What is the output for the code: seq(5,11,by=2,length.out=3)
## Error in seq.default(5, 11, by = 2, length.out = 3): too many arguments
#################### # # # Exercise 4 # # # #################### #What is the output for the code: rep(letters[1:10],3)
## [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "a" "b" "c" "d" "e" "f" "g" ## [18] "h" "i" "j" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
#################### # # # Exercise 5 # # # #################### #Create a sequence with values: #c(100 95 90 85 80 75 70 65 60 55 50) ## seq(100,50,by=-5) #################### # # # Exercise 6 # # # #################### #What is the output for the code: seq(10,0,by=5)
## Error in seq.default(10, 0, by = 5): wrong sign in 'by' argument
#################### # # # Exercise 7 # # # #################### #What is the output for the code: seq(2,10,by=4)==c(2,6,10)
## [1] TRUE TRUE TRUE
#################### # # # Exercise 8 # # # #################### #What is the output for the code: rep(c('seq','rep'),each=4)
## [1] "seq" "seq" "seq" "seq" "rep" "rep" "rep" "rep"
#################### # # # Exercise 9 # # # #################### #Consider two vectors, A and B, A= as.Date("2016-11-01") B = as.Date("2016-11-15") #What is the output for the code: seq.Date(A,B, by = "1 day")
## [1] "2016-11-01" "2016-11-02" "2016-11-03" "2016-11-04" "2016-11-05" ## [6] "2016-11-06" "2016-11-07" "2016-11-08" "2016-11-09" "2016-11-10" ## [11] "2016-11-11" "2016-11-12" "2016-11-13" "2016-11-14" "2016-11-15"
#################### # # # Exercise 10 # # # #################### #Consider two vectors, C and D, C= as.Date("2016-02-01") D = as.Date("2016-06-15") #What is the output for the code: seq.Date(D,C, by = "-1 month")
## [1] "2016-06-15" "2016-05-15" "2016-04-15" "2016-03-15" "2016-02-15"
Leave a Reply