Hello, I have the following dataset. Please note that there are missing values on records 4 and 5:
id,age,weight,height,gender 1,22,180,72,m 2,13,100,67,f 3,5,40,40,f 4,6,42,,f 5,12,98,66, 6,50,255,60,m I'm using the "By" function like this: list1 <- by(dataset[c("weight", "height")], dataset[c("age", "gender")], colMeans, na.rm = TRUE) I then convert the list above to a frame like this: as.data.frame( do.call(rbind, list1) ) I get this output from the code above: weight height 1 40 40 2 42 NaN 3 100 67 4 180 72 5 255 60 I want to get the output above, but I also want two additional columns named "age" and "gender" (with the age and gender values from the "By" function output). How would I do this? Best Regards, Ray DiGiacomo, Jr. Healthcare Predictive Analytics Specialist President, Lion Data Systems LLC President, The Orange County R User Group Board Member, TDWI r...@liondatasystems.com (m) 408-425-7851 San Juan Capistrano, California USA twitter.com/liondatasystems linkedin.com/in/raydigiacomojr youtube.com/user/liondatasystems/videos liondatasystems.com/courses [[alternative HTML version deleted]] ______________________________________________ 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.