I’m getting data from a MySQL table that has 2 columns (idDoc, tag) describing that the document has a given tag. When I use the data frame with
ddply(tags,1)
My objective is to group tags by id, so say I do the following steps
> x=c(1,1,2,2)
> y=c(4,5,6,7)
> data.frame(x,y)
x y
1 1 4
2 1 5
3 2 6
4 2 7
My desired output would be perhaps a list of lists (or whatever other result) that would get
1 -> c(4,5)
2 -> c(6,7)
Regards
This is kind of a shot in the dark, since when you say you want an ‘association’, that doesn’t really precisely describe any particular R data structure, so it’s unclear what form you want the output to take.
But one base R possibility would be to simply use
split:which should returned a named list where the names come from
idDocand each list element is the tags associated with thatidDocvalue. There will be duplicates, though. So maybe this would work better:which should return a list of unique tags for each
idDoc.(Edited: No need for the anonymous function; only need to pass
unique).