[R] Extracting only odd columns from a matrix

Sarah Goslee sarah.goslee at gmail.com
Wed Mar 9 15:32:56 CET 2011


oddvals <- seq(1, ncol(mydata), by=2)
mydata[,oddvals]

On Wed, Mar 9, 2011 at 9:20 AM, Nixon, Matthew <M.R.Nixon at exeter.ac.uk> wrote:
> Hi,
>
> This might seem like a simple question but at the moment I am stuck for ideas. The columns of my matrix in which some data is stored are of this form:
>
> X1     Y1     X2     Y2     X3     Y3     ...     Xn     Yn
>
> with n~100. I would like to look at just the X values (i.e. odd column numbers). Is there an easy way to loop round extracting only these columns?
>
> Any help would be appreciated.
>
> Thank you.


-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list