I am calling table in a loop, so the variable name have to be in a variable itself. Reproducible code below:
library(FactoMineR)
data(hobbies)
htable <- matrix(as.numeric(NA), nrow=18, ncol=7,
dimnames=list( colnames(hobbies)[1:18],
names(with(hobbies,
table(Profession)))))
### Then filling the tables with values:
for(hob in rownames(htable)) {
htable[hob, ] <- with(hobbies, table(hob,
Profession))[2, ]
}
+ + > Error in table(hob, Profession) : all arguments must
have the same length
Somehow, the length of hob is taken as 1, so it is not interpreted in the context of the data frame hobbies? What is wrong?