s-news
[Top] [All Lists]

Re: replacing certain values in a data frame.

To: "Khan, Sohail" <khan@cshl.edu>
Subject: Re: replacing certain values in a data frame.
From: "Vivek Satsangi" <vivek.satsangi@gmail.com>
Date: Wed, 15 Mar 2006 15:33:50 -0500
Cc: s-news@lists.biostat.wustl.edu
Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Vsh3poFdJP7bmqw2Mor1AfUAiBJz+Y0OfwxGvt/cWYRwrhN/h/0/Qa7Dg18bgz5Txj5bkvKbVzE+zsb8KyJMVS2EwHV4hJ7ij4CPDpAt+oSpRdyOUI9CvLrpO1DY743670JGgW/yTnEfSoh/d4S5oZ19OpfkGYQMvzY8W1fVn2k=
In-reply-to: <C8696843AE995F4EA4CDC3E2B83482A901878FB2@mailbox02.cshl.edu>
References: <C8696843AE995F4EA4CDC3E2B83482A901878FB2@mailbox02.cshl.edu>
#Create an example dataframe
a <- 1:10 # Or as large as you want
b <- rep(c("X","Y"),5)
c <- rnorm(10)
df <- data.frame(a,b,c);
df;

# Doing this the long way so that you can see what's happening
# You can do the replace directly, too.
df$replace[df$b=="X"]<-24;
df$replace[df$b=="Y"]<-23;
df$b <- df$replace;
df$replace <- NULL;
df;

# See the frame before and after the sort
df;
df <- df[order(df$c),];
df;

# Be sure to say hi to Dr. Watson for me, will you? :-)


On 3/15/06, Khan, Sohail <khan@cshl.edu> wrote:
> Dear List,
>
> Sorry for asking such a fundamental question.
> I have really large data frame with 3 columns, I want to replace all Y's in 
> column 2 with 24 and all X's with 23, then sort on column 3.  Column 3 is a 
> numeric column, I want to sort in ascending order.
>
> Thanks for any suggestions/advice.
>
> 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
>


--
-- Vivek Satsangi
Student, Rochester, NY USA

Life is short, the art long, opportunity fleeting, experiment
treacherous, judgement difficult.
<Prev in Thread] Current Thread [Next in Thread>