-Ursprüngliche Nachricht-
Von: S Ellison
Gesendet: 07.05.2010 16:44:08
An: r-help@r-project.org,alfred-schu...@web.de
Betreff: Re: [R] Find the three best values in every row
>Hmm...
>
> set.seed(17*11)
> d<-data.frame(africa=sample(50, 10),
>
Using d from the post of S Ellison, try
val <- apply(d, 1, function(x) head(sort(x, decreasing = TRUE), 3))
co <- apply(d, 1, function(x) head(names(d)[order(x, decreasing = TRUE)], 3))
data.frame(values = c(val), countries = c(co), row = c(col(val)))
The first line gives a matrix of the three hi
Hello Alfred,
I found the solution from S. Ellison
(https://stat.ethz.ch/pipermail/r-help/2010-May/238158.html) really
inspiring.
Here I am using tail and the library 'plyr':
set.seed(17*11)
d<-data.frame(africa=sample(50, 10),
europe= sample(50, 10),
n.americ
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
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,
5 matches
Mail list logo