Hi, I would like to create a new column in my dataset X and fill this column with values from dataset Y. Two conditions have to be met (same region and same date). I try to do this by forloop:
for (i in length(X[,1])) { X$Newcolumn <- sapply(1:nrow(X), function(i) Y$Value[Y$region==X$region[i] & Y$date==X$date[i]]) }
But I got this error message: Error in Ops.factor(Y$date, X$date[i]) : level sets of factors are different
date in both datasets has the same format ymd.
What does it mean? I don`t understand why should factors be the same? How can I fix it please? Thanks a lot!