In the following table:
set.seed(5)
df <- data.frame(year=rep(c(2010:2011), each=8),
i=rep(c('66','66','6','6','65','65','6','6'), times=2),
j=rep(c('66','6','66','6','65','6','65','6'), times=2),
count=round(runif(8, 0, 5),0))
There are several events where 'i = j' and 'i != j', I am trying to assign unique values to each of these events. In one scenario where 'i = j' (i.e. 66 = 66 or 6 = 6) I want to assign the value as '0'. However, if 'i != j' I want to assign that event as '1' or higher depending on each unique group e.g., '66_6' or '6_66' is assigned a '1' and '65_6' or '6_65' is assigned a '2'.
So far, I've only been able to figure out how to filter this table to include where these events, such as in the case of group 1 or 2, appear.
x <- df[paste(df$i,df$j,sep = "_") != paste(sapply(strsplit(paste(df$j,df$i,sep = "_"), "\\s+"), function(x) paste(rev(x), collapse=" ")),sep=""),]
If anyone has any advice on how to proceed, I'd appreciate it.