I have a little problem,
i have these parameters:
df <- data.frame(Equip = c(1,1,1,1,1,2,2,2,2,2),
Notif = c(1,1,1,2,2,3,3,3,3,4),
Component = c("Dichtung","Motor","Getriebe","Service","Motor","Lüftung","Dichtring","Motor","Getriebe","Dichtring"),
rank= c(1 , 1 , 1 , 2 , 2 , 1 , 1 , 1 , 1 , 2))
Now i want to have a comparison, looking just for one Equip, and if the used Components in the first rank, are the same as in the second rank ( just by the same Equip):
On 2 ways:
The first: are all Components the same?
Is any( minimum 1) Component the same?
I need a high automatic solution, because my dataset has more than 150k rows.
The desired answer could be a vector with just boolean expressions, including TRUE and FALSE.
So for the example above,
answer <- c(TRUE,TRUE)
Because Equip 1 rank 1 Component: Motor “AND” Equip 1 rank2 is the Component: Motor as well.
( An Example for the 1 desired way)
Thank you very much for your help =)
i used the comment function but i can not show the problem, because i want to show the code.
Please sorry for that..
the original data have more then 2 ranks now i want to combine rank x with rank x+1 in one step,for this is used a for this i used a foor loop in the function but it does not work any idea?
a <- lapply(split(df,df$Equips),function(x){
for(i in 1:8){
ll <- split(x,x$rank)
if(length(ll)>i )
ii <- intersect(ll[[i]]$Comps,ll[[i+1]]$Comps )
else ii <- NA c(length(ii)> 0 && !is.na(ii),ii)
}
})
b <- unlist(a)
c <- table(b,b)
rowSums(c)
any idea what i can do for it ( the main idea is to have the result of 1-2,2-3,3-4 etc in one step!
package
plyris suitable for group manipulationhere I get the the comparaison result and the component name
Edit: here the result with base package(no internet)