Hi R users, I have a dataset with multiple variables and i'm trying to weigh average depths for fish species per year by their abundance (CPUE. I have tried the weighted.mean function but as i have two columns for the x value the lenghts differ with the w (CPUE). How do I solve this problem?
So far I have tried this: data<-by(allspecies, list(allspecies$Depth, allspecies$Year), function(allspecies)weighted.mean(allspecies$CPUE)) but this doesn't seem to give the proper values, as the CPUE values are included. I also have many NA's. When i try to exclude those all my values change. Thanks for your help! much appreciated marjolein -- View this message in context: http://r.789695.n4.nabble.com/weighted-averages-for-two-variables-tp4630589.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.