Hi to all the members of the community, I am trying to find out how to compare elements of my DB and identify them by a new binary variable. My DB is like this:
id=rep((1:2),5)
date<-seq(from=as.Date("2013-01-1"),to=as.Date("2013-01-05"),by=1)
trap<-c(1,1,3,1,4,2,3,4,1,4)
DB<-data.frame(id,date,trap)
DB<-DB[order(DB$date),]
DB$id[2]<-1
DB$trap[2]<-1
result<-c("N","N","N","N","N","N","Y","Y","Y","Y")
DB<-cbind(DB,result)
and I want to identify all the elements for which the id is different, but the date and trap value is the same, as report in the column result.
I have tried some codes (basically derived from another "similar" question) with the ave
function, but unsuccessfully.
As always any tips will be appreciate!!
You could make a double loop over your data frame:
gives: