I\'m trying to calculate the minimum values of a numeric column for each level of a factor, while keeping values of another factor in the resulting data frame.
You need to use merge on result of aggregate and original data.frame
merge
aggregate
data.frame
merge(aggregate(value ~ code, dat, min), dat, by = c("code", "value")) ## code value index ## 1 HH11 24.1 023434 ## 2 HH45 37.2 3377477 ## 3 JL03 20.0 1177777