You can use data.table
library(data.table) DT <- data.table(df) setkey(DT, Position) DT[, .SD[J(1:5), roll=FALSE], by=Name][order(Name, Position),]
Or you can use tidyr/dplyr
library(dplyr) library(tidyr) df %>% spread(Position, Value) %>% gather(Position, Value, `1`:`5`) %>% arrange(Name, Position)
data
df <- structure(list(Name = c("a", "a", "a", "b", "b", "b", "c", "c", "c", "d", "d", "d"), Position = c(1L, 3L, 4L, 1L, 2L, 5L, 2L, 3L, 5L, 1L, 2L, 3L), Value = c(0.2, 0.4, 0.3, 0.5, 0.4, 0.3, 0.3, 0.4, 0.1, 0.2, 0.4, 0.5)), .Names = c("Name", "Position", "Value"), class = "data.frame", row.names = c(NA, -12L))