I have to change the column names inside table function. But the issue is I have used for loop, so I am taking i and j to name column names. Below is the code. If you observe, in proptable
i have used i and j but not working. The output is coming as i and j only . I need the respective column names as defined in for loop
df <- structure(list(Product = structure(c(2L, 1L, 3L), .Label = c("Product 100",
"Product 75", "Product 87"), class = "factor"), Product.Family = structure(c(1L,
2L, 2L), .Label = c("Product.Family 43", "Product.Family 48"), class = "factor"),
ColA = structure(1:3, .Label = c("A", "B", "C"), class = "factor")), class = "data.frame", row.names = c(NA,
-3L))
p326 <- list()
bs <- names(Filter(is.factor, df))
for(i in bs)
for(j in bs) {
p326[[i]][[j]] <- as.data.frame(prop.table(table(i=df[,i],j=df[,j]), margin=1)*100)
do.call(rbind,p326) %>% as.data.frame()
}