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
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,
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
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
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
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
?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
7 matches
Mail list logo