You have two options. Indexing the multiple occurrences for each level of Bulls
or using a list to hold the different levels of EBV
.
Option 1: Indexing multiple occurrences
You can use data.table
to generate an index that numbers multiple occurrences of EBV
:
require(data.table)
setDT(all) ## convert to data.table
all[, index:=1:.N, by=Bulls] ## generate index
dcast.data.table(all, formula=index ~ Bulls, value.var='EBV')
Option 2: Using a list to store multiple values
You could use a list as a value with data.table
(I'm not sure if plain data.frame
supports it).
require(data.table)
setDT(all) ## convert to data.table
all[, list(list(EBV)), by=Bulls] ## multiple values stored as list