#Would like to create a cross-table (Region, district, response) and #(Region, district, cost. The flat table function does not look so good region <- c("A","A","A","A","B","B", "B", "B", "C","C", "C", "C") district <- c("d","d","e","e","f","f", "g", "g", "h","h", "i", "j") response <- c("yes", "no", "yes", "yes", "no", "yes", "yes", "no", "yes", "no", "yes","no") cost <- runif(12, 5.0, 9) var <- c("region", "response", "district") data <- data.frame(region, district, response, cost) var1 <- c("region", "district", "response") var2 <- c("region", "district", "cost") data1 <- data[var1] #This look okay with(data, aggregate(x=cost, by=list(region, district), FUN="mean")) #This does not look good #How do i remove the NaN or create a better one prop.table(ftable(data1, exclude = c(NA, NaN)), 1) prop.table(ftable(xtabs(~region + district+ response, data=data)),1)
Peter Maclean Department of Economics UDSM [[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.