#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.
|