Skip to content
Back to formatted view

Raw Message

Message-ID: <39B6DDB9048D0F4DAD42CB26AAFF0AFA076CE3@usctmx1106.merck.com>
Date: 2005-03-25T13:24:14Z
From: Liaw, Andy
Subject: newbie's question about dataframe

Something like this should do it:

 dat$Z <- with(dat, as.numeric(Y >= Y[order(Y, decreasing=TRUE)[10]]))

Andy

> From: Wensui Liu
> 
> I have a dataframe containing X and Y. Right now, I want to create
> another variable in the dataframe, named Z, such that for Z = 1 for
> the top 10 largest value of Y and Z = 0 for the rest values of Y.
> 
> I really appreciate your help. Have a great weekend.
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
> 
>