1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

R language, seq and rep problem

  1. Dec 16, 2014 #1
    1. The problem statement, all variables and given/known data
    Using rep() and seq() as needed, create the vector
    1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 4 5 6 7 8 5 6 7 8 9

    2. Relevant equations


    3. The attempt at a solution
    I figured out that seq() only takes numbers for the 'from' and 'to' arguments, since I tried seq(seq(...)).

    Also, I'm not repeating the same sequence, so I'm not seeing how rep would work here. 1 and 9 are not repeated. 2,8 are appear twice. 3 and 7 are appear 3 times. And 4,5 are appear 4 times. rep(...,times) and rep(...,each) don't seem to work for this.

    I can solve this using c(seq(1,5),...,seq(5,9)), although it seems the problem should be solved using only rep and seq.

    I'm stumped here.
     
  2. jcsd
  3. Dec 17, 2014 #2
    well you should try this. rep()
    {
    i = 1;
    seq(i,i+4);
    i++;
    }
    and check when i>5 then exit.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: R language, seq and rep problem
  1. C language problem ? (Replies: 13)

Loading...