r - Condense "flat" list of occurrences for analysis with arules eclat -
I have a file that looks like this (list of person ID and product name)
123 A 123b 123D 456A456B 123C
And I want to change it in such a way for use with AVLat (list of products purchased by each person )
list (C ("A", "B", "D", "C"), C ("A", "B"))
The best I've been able to do is read it as a data frame, and new day Received strucutre is to try to use variants of applying the function to create.
collectValues & lt; - Function (Obs, map) {a = obs [1] [1] b = obs [2] [1] If (! (%% In map%)) {map [[a]] & lt; - list (b)} Else {c (map [[A]], b)}}
But I'm also new to R for working R ...
I think that after you split
:
dat < - read.table (text = "123 A 123b 123D 456A456B 123C", header = F.LESE, string AFFactors = falls) splitting (split (DT [, 2], DAT [, 1]), sort ### $ 123` ## [1] "A" "B" C "D" ## ## $ `456` ## [1]" A "" B "
< P> I used sort
with empty
that you want the desired output you see, but you do not need it.
Comments
Post a Comment