Hi, Try: dat <- structure(list(Custom = c("Judi", "Judi", "Ben", "Tom", "Tom", "Bill", "Lindy", "Shary", "Judu", "Judu", "Billy", "Tommy", "Tommy", "Benjum", "Linda", "Shiry"), Gender = c("Female", "Female", "Male", "Male", "Male", "Male", "Female", "Female", "Female", "Female", "Male", "Male", "Male", "Male", "Female", "Female"), Product = c("A", "B", "A", "A", "B", "B", "A", "B", "A", "B", "A", "A", "B", "B", "A", "B"), Payment = c("Credit Card", "Credit Card", "Cash", "Cash", "Cash", "Credit Card", "Cash", "Credit Card", "Credit Card", "Credit Card", "Cash", "Cash", "Cash", "Credit Card", "Cash", "Credit Card")), .Names = c("Custom", "Gender", "Product", "Payment" ), class = "data.frame", row.names = c(NA, -16L))
dat1 <- within(dat, Categ <- ave(Product, Custom, FUN= function(x) if(length(x)>1) "A and B" else x)) library(reshape2) res <- acast(dat1,Categ~Gender+Payment,length,value.var="Categ") #or dcast() res[2,] <- res[2,]/2 res A.K. Hello experts, I am a beginner of R and need your kind help for a R question. Any advice will be greatly appreciated. I have a sample data set like below: Customs purchase either product A or B or both using either Credit card or Cash. I would like to summarize the data as a crosstab in R ---- show how many customs purchase product A only or product B only or product A and B using either credit card or cash. Is that possible in R? Thank you very much for your time and help. Customer_Sample.xlsx ______________________________________________ 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.