s-news
[Top] [All Lists]

Re: Selecting every other line from a data frame

To: "Khan, Sohail" <khan@cshl.edu>
Subject: Re: Selecting every other line from a data frame
From: Tony Plate <tplate@blackmesacapital.com>
Date: Fri, 21 Apr 2006 11:32:29 -0600
Cc: christos@nuverabio.com, s-news@lists.biostat.wustl.edu
In-reply-to: <C8696843AE995F4EA4CDC3E2B83482A901879011@mailbox02.cshl.edu>
References: <C8696843AE995F4EA4CDC3E2B83482A901879011@mailbox02.cshl.edu>
User-agent: Mozilla Thunderbird 1.0.5 (Windows/20050711)
In general, it's wise to avoid the idiom 1:n, because when n is zero, this generates the vector c(1,0), which is rarely (ever?) what you want. Instead use seq(len=n).

The R-faq has some pointers to some good books on S-PLUS & R. Find it at www.r-project.org.

-- Tony Plate

Khan, Sohail wrote:
Thanks Tony and Chritos. Its great!!

Could you recommend a good S book to learn this sort of stuff?

-Sohail

-----Original Message-----
From: s-news-owner@lists.biostat.wustl.edu
[mailto:s-news-owner@lists.biostat.wustl.edu]On Behalf Of Christos
Hatzis
Sent: Friday, April 21, 2006 11:53 AM
To: christos@nuverabio.com; Khan, Sohail; s-news@lists.biostat.wustl.edu
Subject: Re: [S] Selecting every other line from a data frame


Sorry it should be:
my.df[ (1:nrow(my.df)) %% 2 == 0, ]

-----Original Message-----
From: s-news-owner@lists.biostat.wustl.edu
[mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Christos Hatzis
Sent: Friday, April 21, 2006 11:51 AM
To: 'Khan, Sohail'; s-news@lists.biostat.wustl.edu
Subject: Re: [S] Selecting every other line from a data frame

You can try the following:

my.df[ nrow(my.df) %% 2 == 0, ]

for selecting even lines or == 1 for odd lines.

-Christos
-----Original Message-----
From: s-news-owner@lists.biostat.wustl.edu
[mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Khan, Sohail
Sent: Friday, April 21, 2006 11:46 AM
To: s-news@lists.biostat.wustl.edu
Subject: [S] Selecting every other line from a data frame

Dear All,

I have a large data frame, from which I want to only select every other line
or odd lines.
How can I do this?  Thanks.


Sohail Khan
Scientific Programmer
COLD SPRING HARBOR LABORATORY
Genome Research Center
500 Sunnyside Boulevard
Woodbury, NY 11797
(516)422-4076

--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with the
BODY of the message:  unsubscribe s-news



--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with the
BODY of the message:  unsubscribe s-news



--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news


<Prev in Thread] Current Thread [Next in Thread>