[R] Vector manipulation

2012-02-12 Thread syrvn
Hello, I am stuck with the following problem. Consider the vector: vec - c(2,4,6,9,10) I now want to use R to manipulate the vector as follows: [1] 2, 4, 2, 6, 2, 9, 2, 10 In words, the first element of the vector should be placed in front of each following number. Which R commands do I

Re: [R] Vector manipulation

2012-02-12 Thread Dimitris Rizopoulos
One way is: vec - c(2,4,6,9,10) c(rbind(vec[1], vec[-1])) I hope it helps. Best, Dimitris On 2/12/2012 6:54 PM, syrvn wrote: Hello, I am stuck with the following problem. Consider the vector: vec- c(2,4,6,9,10) I now want to use R to manipulate the vector as follows: [1] 2, 4, 2, 6,

Re: [R] Vector manipulation

2012-02-12 Thread Jorge I Velez
Hi mentor_, Try c(sapply(vec[-1], function(x) c(vec[1], x))) # [1] 2 4 2 6 2 9 2 10 HTH, Jorge.- On Sun, Feb 12, 2012 at 12:54 PM, syrvn wrote: Hello, I am stuck with the following problem. Consider the vector: vec - c(2,4,6,9,10) I now want to use R to manipulate the vector

Re: [R] Vector manipulation

2012-02-12 Thread syrvn
Great Dimitris. It helps indeed! Thanks a lot! -- View this message in context: http://r.789695.n4.nabble.com/Vector-manipulation-tp4381586p4381614.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list

[R] Vector manipulation, for loop needed?

2010-06-18 Thread clips10
Hi, I have a vector of time in days t-1:48. I have observations and the day they were recorded. I also have a vector, S which takes different values depending on which day the observation was recorded. For example if on day 1 all in vector S get a value of 46/48, on day 2 get 42/48, day 3

Re: [R] Vector manipulation, for loop needed?

2010-06-18 Thread David Winsemius
On Jun 18, 2010, at 10:52 AM, clips10 wrote: Hi, I have a vector of time in days t-1:48. I have observations and the day they were recorded. I also have a vector, S which takes different values depending on which day the observation was recorded. For example if on day 1 all in vector S

Re: [R] Vector manipulation, for loop needed?

2010-06-18 Thread Jorge Ivan Velez
?ifelse HTH, Jorge On Fri, Jun 18, 2010 at 10:52 AM, clips10 wrote: Hi, I have a vector of time in days t-1:48. I have observations and the day they were recorded. I also have a vector, S which takes different values depending on which day the observation was recorded. For example if