I\'m pretty new to R and have a question regarding selecting the max values in a column.
I have the following data frame:
X Y
[1,]
You can use ave with a custom function that wraps max, so you can remove NA values:
Data$Y <- ave(Data$Y, Data$X, FUN=function(x) max(x, na.rm=TRUE))
With the dplyr or data.table packages, you get an easy way group to calculate grouped operations.
dplyr solution
require(dplyr)
Data %>% group_by(X) %>% mutate(Y = max(Y, na.rm=TRUE))
data.table solution
require(data.table)
setDT(Data)[, Y:=max(Y, na.rm=TRUE), by=X][]