Hmm...

 set.seed(17*11)
 d<-data.frame(africa=sample(50, 10), 
                europe= sample(50, 10),
                n.america= sample(50, 10),
                s.america= sample(50, 10),
                antarctica= sample((1:50)/20, 10)
                )

#Get three top from each row
t(apply(d,1,function(x,n) x[which(rank(x)> length(x)-n)], n=3))

#Get them with names
get.n<- function(x, names, n)   {
        rmin<- 
        rv<-x[w<-which(rank(x)> length(x)-n)]
        names(rv)<-names[w]
        return(as.data.frame(rv))
}

apply(d,1,get.n, n=3, names=names(d))



>>> Alfred Schulze <alfred-schu...@web.de> 05/07/10 2:43 PM >>>

   Hello,

   i have a dataframe with the GDP for different Country (in the
columns) and
   Years (in the rows).

   Now i want for every year the best three values, if possible with
name of
   the countries (columnnames).

   For the best it's no problem but for the other two values.

   Thanks,

   Alfred
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to