Dear list, I am trying to make a contingency table with xtabs but I am getting a 0 where I expect a 'NA'. Here is a simple example:
options(stringsAsFactors = FALSE) rn <- LETTERS[1:4] df1 <- data.frame(r07 = rep(rn, each=4), r08 = rep(rn, 4), value = 1:16) xtabs(value ~ r07 + r08, df1) # Delete the combination [A, C] df1 <- df1[-3,] # Set 'value' for this combination to 0 df1[13, 3] <- 0 # This is the output I want tapply(df1[, "value"], df1[, c("r07", "r08")], c) # but using 'xtabs' I get a 0 for [A, C] xtabs(value ~ r07 + r08, df1) Hmm, what have I missed... Thanks for any help! Best, Patrick ______________________________________________ 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.