I am new to R and asking a question about choosing maximum values ββin a column.
I have the following data frame:
XY [1,] 1 10 [2,] 1 12 [3,] 1 NA [4,] 2 5 [5,] 2 6 [6,] 2 7 [7,] 2 8 [8,] 3 NA [9,] 3 NA [10,] 3 1
I would like to select the maximum value of the Y column and replace all the Y values ββwithin each group with this value. My output data frame will look like this:
XY [1,] 1 12 [2,] 1 12 [3,] 1 12 [4,] 2 8 [5,] 2 8 [6,] 2 8 [7,] 2 8 [8,] 3 1 [9,] 3 1 [10,] 3 1
Any help would be greatly appreciated. Thanks!
Data here
Data <- structure(list(X = c(1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L), Y = c(10L, 12L, NA, 5L, 6L, 7L, 8L, NA, NA, 1L)), .Names = c("X", "Y"), class = "data.frame", row.names = c("[1,]", "[2,]", "[3,]", "[4,]", "[5,]", "[6,]", "[7,]", "[8,]", "[9,]", "[10,]"))