How do you access the different dimensions in a table in R ( table() function)?

131 Views Asked by At

I created a multidimensional contingency table in R using the table() function.

Here's the code I used to create my table:


    tab <- table(nba$zoneBasic, nba$close_def_dist, nba$touch_time,nba$period, nba$off_dribble, 
    dnn=c('Zone','Closest Defender Distance','Touch Time','Quarter','Off Dribble'))

    tab

And here is a screenshot of a portion of the output:

enter image description here

How do I access the different dimensions as shown in the output and convert them into separate tables? I've tried indexing (tab[1]) as a simple way to access the dimensions, but that doesn't work since table() isn't actually creating separate tables as it appears in the output.

1

There are 1 best solutions below

0
akrun On

It is a multi-dimensional array. An easier option is to convert to long format to data.frame

df1 <- as.data.frame(tab)

Or if we want a single table use ftable

ftable(nba[c("zoneBasic", "close_def_dist",
   "touch_time" , "period", "off_dribble")]