The most intuitive method is to use group_by
and top_n
function in dplyr
group %>% group_by(Subject) %>% top_n(1, pt)
The result you get is
Source: local data frame [3 x 3]
Groups: Subject [3]
Subject pt Event
(dbl) (dbl) (dbl)
1 1 5 2
2 2 17 2
3 3 5 2
Related Contents:
- Reshaping data.frame from wide to long format
- How to sum a variable by group
- How do I make a list of data frames?
- Aggregate / summarize multiple variables per group (e.g. sum, mean)
- Dynamically select data frame columns using $ and a character value
- Sort (order) data frame rows by multiple columns
- Numbering rows within groups in a data frame
- The difference between bracket [ ] and double bracket [[ ]] for accessing the elements of a list or dataframe
- Simultaneously merge multiple data.frames in a list
- Split data frame string column into multiple columns
- Calculate the mean by group
- Filter data.frame rows by a logical condition
- Count number of rows within each group
- Quickly reading very large tables as dataframes
- Remove rows with all or some NAs (missing values) in data.frame
- Drop unused factor levels in a subsetted data frame
- Split data.frame based on levels of a factor into new data.frames
- Subset data frame based on number of rows per group
- Combine a list of data frames into one data frame by row
- Combine two data frames by rows (rbind) when they have different sets of columns
- Counting unique / distinct values by group in a data frame
- Pass a data.frame column name to a function
- Drop data frame columns by name
- How to split a data frame?
- Why is it not advisable to use attach() in R, and what should I use instead?
- Create an empty data.frame
- How to plot all the columns of a data frame in R
- Sample random rows in dataframe
- Extracting specific columns from a data frame
- Subset / filter rows in a data frame based on a condition in a column
- How does one reorder columns in a data frame?
- Rename multiple columns by names
- Convert data.frame column format from character to factor
- Combine two or more columns in a dataframe into a new column with a new name
- Re-ordering factor levels in data frame [duplicate]
- Should I use a data.frame or a matrix?
- Convert a dataframe to a vector (by rows)
- Dollar sign before a variable
- Apply several summary functions on several variables by group in one call
- How to sort a character vector where elements contain letters and numbers in R?
- Fitting a density curve to a histogram in R
- R Reshape data frame from long to wide format? [duplicate]
- Calculate row means on subset of columns
- Fastest way to add rows for missing time steps?
- Get last row of each group in R [duplicate]
- Variable name restrictions in R
- Apply several summary functions (sum, mean, etc.) on several variables by group in one call
- Subsetting a data frame based on contents of another data frame
- Remove all rows where length of string is more than n
- How can I change XTS to data.frame and keep Index?