In R, say I have the following dataset:
st<-data.frame(codigo=c("24","24","24","24","25","25","25","25"),
color=c("grey","blue","white","white","black","blue","green","black"),
talle=c(1:4,1:4),
precio=c("200","200","200","400","100","100","100","100"),
codigo2=c("24","NA","NA","24","25","NA","NA","NA"),
color2=c("NA","NA","NA","NA","NA","NA","NA","NA"),
talle2=c("NA","NA","NA","4","NA","NA","NA","NA"),
precio2=c("200","NA","NA","400","100","NA","NA","NA"))
There are "codigo2", "color2", "talle2", "lista2","precio2" columns in the right which were created using the values of the columns in the left. rows from columns in the lef differ in the value of "codigo", "talle" and/or "price". What I want to do is that when the value of "codigo" of the inferior row is the same as the superior row and the value of "precio" of the inferior row is the some as the superior row, all the inferior row must be empty, however, if "precio" changes, then the infirior row must show its value of, and only, "codigo", "talle" and "precio" . If the value of "codigo" of the inferior row compared with the superior row is different, then the inferior row must have the value of "codigo" and "precio", and then repete the procedure all over again till the end of the rows.
clearley I don´t have enough knowledge to do this, I´ve tried this:
preciosdupli2<- df %>% group_by(Artículo,Talle,LISTA1) %>% filter (!duplicated(Artículo,Talle,LISTA1)
and also this:
talleunico<-df%>%distinct(Talle) preciosdupli2<- df %>% group_by(Artículo,Talle,LISTA1) %>% filter (!duplicated(Artículo,Talle==talleunico,LISTA1))