My df is as below:
set.seed(123)
df <- data.frame(x = sample(letters[1:3],20,replace = TRUE),
y = sample(1:10,20,replace = TRUE))
df <- df[order(df$x),]
I want to replace the first value of each group with NA. For example:
x y
a NA
a 8
a 1
a 8
b NA
b 3
b 2
b 10
b 8
.
.
I've no problem with get first values but that's not meaningful.
test <- df %>%
group_by(x) %>%
do(a = head(.$y,1))
Please help next step.