I have a data framework containing a set of parts and test results. Parts are tested at 3 sites (North Center and South). Sometimes these parts are rechecked. I want, in the end, to create several diagrams that compare the results from the first time, when the part was tested with the second (or third, etc.) Time that was checked, for example. to view the repeatability of the tester.
As an example, I have given the code below. I explicitly deleted the Experiment column from the morley dataset, as this is the column I'm really trying to recreate. The code works, however it seems that there should be a more elegant way to approach this problem. Any thoughts?
Edit - I understand that the above example was too simplistic for my real needs (I tried to create a reproducible example as simple as possible).
New example:
part<-as.factor(c("A","A","A","B","B","B","A","A","A","C","C","C"))
site<-as.factor(c("N","C","S","C","N","S","N","C","S","N","S","C"))
result<-c(17,20,25,51,50,49,43,45,47,52,51,56)
data<-data.frame(part,site,result)
data$index<-1
repeat {
if(!anyDuplicated(data[,c("part","site","index")]))
{ break }
data$index<-ifelse(duplicated(data[,1:2]),data$index+1,data$index)
}
data
part site result index
1 A N 17 1
2 A C 20 1
3 A S 25 1
4 B C 51 1
5 B N 50 1
6 B S 49 1
7 A N 43 2
8 A C 45 2
9 A S 47 2
10 C N 52 1
11 C S 51 1
12 C C 56 1
Old example:
df<-morley[,c(2,3)]
df$index<-1
repeat {
if(!anyDuplicated(df[,c(1,3)]))
{ break }
df$index<-ifelse(duplicated(df[,c(1,3)]),df$index+1,df$index)
}
df$index==morley$Expt