data.frame
and split
will do it:
pets <- data.frame(
name=c("Amy", "Bob", "Carol", "Danny", "Eustace", "Frances"),
animal=c("dog", "cat", "dog", "cat", "horse", "horse")
)
data.frame(split(pets$name,pets$animal,drop=TRUE))
# cat dog horse
#1 Bob Amy Eustace
#2 Danny Carol Frances
pets2 <- pets[1:2,]
data.frame(split(pets2$name,pets2$animal,drop=TRUE))
# cat dog
#1 Bob Amy