the logic code is: each different client(can have more 2 client) has output ==1 index value should increment (3* client),
if output ==2 index value 10
condition not working is
mydf$client[i]!=count in part not able increment count
mydf <- data.frame(time = c(2,4,3,2,3,3,3,4,4,4,3,2,4,3,2,4,4,2,2), output = c(1,1,2,2,1,1,1,1,1,2,1,1,1,1,1,2,1,1,1), client =c(1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2)) mydf$index<-0 count=1 (i in 1:length(mydf)) { repeat { if(mydf$client[i]==count) { if(mydf$output[i]==1 ) { mydf$index[i]<-3*count } if(mydf$output[i]==2 ) { mydf$index[i]<-10 } } if(mydf$client[i]!=count ) { count<-count+1 } if(mydf$client[i]<3) {break } } } time output client index 2 1 1 3 4 1 1 3 3 2 1 10 2 2 1 10 3 1 2 6 3 1 2 6 3 1 2 10 4 1 2 10 4 1 2 6 4 2 2 10 3 1 2 6 2 1 2 6 4 1 2 10 3 1 2 6 2 1 2 6 4 2 2 10 4 1 2 6 2 1 2 6 2 1 2 10
thanks in advance
Comments
Post a Comment