Hi, is there an R function like sql's TOP key word?
I have a dataframe that has 3 columns: company, person, salary
How do I get top 5 highest paid person for each company, and if I have
fewer than 5 people for a company, just return all of them?
Thanks,
Richard
tmp - data.frame(matrix(rnorm(30), 10, 3,
dimnames=list(letters[1:10],
c(company, person, salary
tmp
company person salary
a -1.04590176 -0.7841855 1.07150503
b -1.06643101 0.6545647 0.43920454
c
-project.org
Subject: Re: [R] get top n rows group by a column from a dataframe
tmp - data.frame(matrix(rnorm(30), 10, 3,
dimnames=list(letters[1:10],
c(company, person,
salary
tmp
company person salary
]
Sent: Thursday, September 16, 2010 11:53 AM
To: Tan, Richard
Cc: r-help@r-project.org
Subject: Re: [R] get top n rows group by a column from a dataframe
tmp - data.frame(matrix(rnorm(30), 10, 3,
dimnames=list(letters[1:10],
c
list. I don't see how your way can work?
Thanks,
Richard
From: RICHARD M. HEIBERGER [mailto:r...@temple.edu]
Sent: Thursday, September 16, 2010 11:53 AM
To: Tan, Richard
Cc: r-help@r-project.org
Subject: Re: [R] get top n rows group by a column from a dataframe
tmp - data.frame
Thanks, it works.
Richard
From: Henrique Dallazuanna [mailto:www...@gmail.com]
Sent: Thursday, September 16, 2010 1:56 PM
To: Tan, Richard
Cc: RICHARD M. HEIBERGER; r-help@r-project.org
Subject: Re: [R] get top n rows group by a column from a dataframe
You can try this:
(Using
-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Tan, Richard
Sent: Thursday, September 16, 2010 8:39 AM
To: r-help@r-project.org
Subject: [R] get top n rows group by a column from a dataframe
Hi, is there an R function like
Hi:
You already have some good solutions; here is another using the plyr
package, based on a slight modification in salary from Phil Spector's test
data:
sdata = data.frame(company=sample(LETTERS[1:8],1000,replace=TRUE),
person=1:1000,
salary=
8 matches
Mail list logo