Skip to content
Back to formatted view

Raw Message

Message-ID: <B37C0A15B8FB3C468B5BC7EBC7DA14CC62F7AA37FA@LP-EXMBVS10.CO.IHC.COM>
Date: 2010-01-18T17:18:35Z
From: Greg Snow
Subject: Choose every second value
In-Reply-To: <4B52F26A.1040502@googlemail.com>

In addition to the other suggestions, you can use logical subsetting with autoreplication:

> x <- 1:6
> x[ c(T,F) ]
[1] 1 3 5
> x[ c(F,T) ]
[1] 2 4 6



-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Walther, Alexander
> Sent: Sunday, January 17, 2010 4:20 AM
> To: r-help at r-project.org
> Subject: [R] Choose every second value
> 
> 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.