I am new to r and any help would be appreciated.
I want to get a sequence of numbers from 1 to 365 in certain steps. when my first number starts from anything more than one, i want my code to print the number till/before 365 depending on the steps and then start from 1 again till it reaches the number it started from.
firstnumber=20 steps=10 lastnumber=0 if(firstnumber > 1){lastnumber = 365 + firstnumber - (steps)} else{lastnumber = 365} for(number in seq(firstnumber, lastnumber, steps)) { if(firstnumber > 1) { if(number + steps > 365) {number = (number + steps - 365) } } print(date) }it should give me [1] 20 [1] 30 [1] 40 [1] 50 [1] 60 [1] 70 [1] 80 [1] 90 [1] 100 [1] 110 [1] 120 [1] 130 [1] 140 [1] 150 [1] 160 [1] 170 [1] 180 [1] 190 [1] 200 [1] 210 [1] 220 [1] 230 [1] 240 [1] 250 [1] 260 [1] 270 [1] 280 [1] 290 [1] 300 [1] 310 [1] 320 [1] 330 [1] 340 [1] 350 [1] 360 [1] 5 [1] 15
but it misses the 360 which is the last number before it goes to the start of the sequence Is something wrong with the if condition? or is there another way of doing this?
Aucun commentaire:
Enregistrer un commentaire