Hi guys, I have two data frames: one referred to 2008 and one to 2009. Their structure is identical except for the different data in them. I need to create a vector alfa of the same length of the dataframe 2009 and fill each element with the mean of 2008$var1 conditional to the subgroup indicated by a factor variable in 2009$var2. In this case it would be easy to use the function alfa[i]<-ave(2008$var1,2008$var2==2009$var2[i],FUN=mean). The problem is that 2008$var2 and 2009$var2 contain both 20 levels each but only 18 of them are shared. So for those 18 I need to find the result that I`d get applying the above formula (which in any case doesnt work if the levels are not identical in the two data frames colmns) and for those two different levels in 2009$var2 to use the average of the whole column 2008$var2. Anybody has some ideas? Please help me... Hope it`s clear enough what I need. Thanks! alberto -- View this message in context: http://r.789695.n4.nabble.com/conditional-mean-between-two-data-frames-with-different-levels-tp3049010p3049010.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help@r-project.org 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.