It depends quite strongly on what you want to do with the result, but I wonder if what is really needed might be a list of diettypes per person, i.e. continuing from Eric's code
> On 25 Feb 2018, at 18:56 , Eric Berger <ericjber...@gmail.com> wrote: > > Hi Allaisone, > I took a slightly different approach but you might find this either as or > more useful than your approach, or at least a start on the path to a > solution you need. > > df1 <- > data.frame(CustId=c(1,1,1,2,3,3,4,4,4),DietType=c("a","c","b","f","a","j","c","c","f"), > stringsAsFactors=FALSE) > with(df1, tapply(DietType, CustId, list)) $`1` [1] "a" "c" "b" $`2` [1] "f" $`3` [1] "a" "j" $`4` [1] "c" "c" "f" or maybe get rid of duplicates with > with(df1, tapply(DietType, CustId, unique)) $`1` [1] "a" "c" "b" $`2` [1] "f" $`3` [1] "a" "j" $`4` [1] "c" "f" -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd....@cbs.dk Priv: pda...@gmail.com ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.