Skip to content
Back to formatted view

Raw Message

Message-ID: <4B52F3A3.2080808@erasmusmc.nl>
Date: 2010-01-17T11:25:23Z
From: Dimitris Rizopoulos
Subject: Choose every second value
In-Reply-To: <4B52F26A.1040502@googlemail.com>

try this:

a <- c(1,2,3,4,5,6)

n <- length(a)
a[seq(1, n, 2)]
a[seq(2, n, 2)]


I hope it helps.

Best,
Dimitris


Walther, Alexander wrote:
> Dear list,
> 
> is there a command that selects every second value from a given vector?
> For instance,
> 
> a <- c(1,2,3,4,5,6)
> 
> should yield
> 
> 1,3,5
> 
> and
> 
> 2,4,6
> 
> which i intend to place into two seperate vectors.
> 
> 
> best
> 
> Alex
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014