I am new to R and was looking for some help. I understand that the following problem is quite simple and is looking for similar questions. No one gives quite the answer I'm looking for - any help would be appreciated.
Problem:
Creating a frequency table using the table() function for three variables with data in the format:
Var1 Var2 Var3 1 0 1 0 2 0 1 0 3 1 1 1 4 0 0 1
Where, 0 = "No" and 1 = "Yes"
And the summary table is in the following format with variables and values indicated:
Var3 Yes No Var1 Yes 1 0 No 1 2 Var2 Yes 1 2 No 1 0
What I have tried so far:
Using the following code, I can create a variable table 2 with labels for variables, but not for values (i.e. No and Yes).
table(data$Var1, data$Var3, dnn = c("Var1", "Var3"))
It looks like this:
Var3 Var1 0 1 0 2 1 1 0 1
When I try to mark the values of rows and columns (0 = No and 1 = Yes), I understand that row.names and responseName can be used, however, the following attempt to label row names gives an error all arguments must have the same length .
> table(data$Var1, data$Var2, dnn = c("Var1", "Var2"), row.names = c("No", "Yes"))
I also tried using ftable() , however the table shape created using the code below is incorrect, which leads to the wrong frequencies for the problem. The problem with marking row and column values remains.
> ftable(data$Var1, data$Var2, data$Var3, dnn = c("Var1", "Var2", "Var3")) Var3 0 1 Var1 Var2 0 0 0 1 1 2 0 1 0 0 0 1 0 1
Any help on using table() to get the table of the desired shape would be greatly appreciated.