If you want a row for each unique item:
> example <- data.frame(id=rep(
+ ( abs(round(rnorm(50,mean=500,sd=250),digits=0)))
+ ,3), group=rep(1:15,10))
> example <-example[with(example,order(id,group)),]
>
> uniqueIDs <- do.call(rbind
+ , lapply(split(example, example$group), function(.grp){
+
Is this close to what you want:
> example <- data.frame(id=rep(
+ ( abs(round(rnorm(50,mean=500,sd=250),digits=0)))
+ ,3), group=rep(1:15,10))
> example <-example[with(example,order(id,group)),]
>
> uniqueIDs <- do.call(rbind
+ , lapply(split(example, example$group), function(.grp){
+
Dear R experts,
I am having difficulty using loops productively and would like to please
ask for advice. I have a dataframe of ids and groups. I would like to
break down the dataframe into groups, find the unique sets of ids, then
reassemble. My thought was to use a loop, but I have been unable
3 matches
Mail list logo