Say I have a vector of elements divided by group, I am looking for a way of getting the ordered selection of elements without repeatition by group. The example will probably clarify:
group<-c("a","a","a","b","b","b")
element<-c(1,2,3,1,2,3)
data<-data.frame(group,element)
I would like to get:
group<-c("a","a","a","b","b","b")
element.x<-(1,1,2,1,1,2)
element.y<-(2,3,3,2,3,3)
data<-data.frame(group, element.x,element.y)
I have tried to work with left_join from dplyr but it gives me all the combinations (i.e. (1,2) and (2,1) and it is not what I am looking for).
require(dplyr)
data<- data %>%
left_join(data , by=c("group"))
Possibly, I would prefer something that can work even if the variable "element" is a string. Thanks a lot.