Dear R community,
I would like to merge two datasets based on the categorical predictor
country.
Dataset A:
Country Measure1
Afganistan 1
Afganistan 1
Russia 5
Poland 3
Poland 2
Dataset B:
Country Measure 2
Russia 2
Afganistan 10
Poland 15
My program does not work:
Country_A<-A$Country
Country_B<-B$Country
Measure2<-B$Measure2
for(i in 1:nrow(B)){
for(j in 1:nrow(A){
w[j]<-ifelse(Country_A[j]= =(Country_B[i]),Measure2[i], NA)
}}
A2<-cbind(B,w)
Thanks, Julia
_________________________________________________________________
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.