We can use table
on the 'x' column with the sequence of rows and cbind
with the original dataset
res <- cbind(df, as.data.frame.matrix(table(seq_len(nrow(df)), df$x)))
names(res) <- tolower(make.names(names(res)))
res
# x y x1 x2 x3 x4 x5
#1 1 ola 1 0 0 0 0
#2 2 ola 0 1 0 0 0
#3 3 ola 0 0 1 0 0
#4 5 ola 0 0 0 0 1
#5 4 ola 0 0 0 1 0
#6 2 ola 0 1 0 0 0