I got this error:

Error in table(st2.affect) : attempt to make a table with >= 2^31 elements

when I tried to use function (or any other proportions function) such as:

proportions(table(st2.affect), margin = 1L)

My dataset has 20 categorical variables with 5 levels which are very important for the analysis. I still tried to do the proportion table without levels and got the same error. I want to know frequencies and proportions of each variable and I want to create a table with proportions.

What is the solution to this error?

Data set sample:

There are 20 areas (variable) Each participant assigned one of 5 affective labels

 area1_affect area2_affect area3_affect area4_affect area5_affect 
 Peaceful     Peaceful     Peaceful     Tense        Peaceful       
 Other        Peaceful     Other        Other        Other           
 Peaceful     Peaceful     Peaceful     Tense        Tense           
 Peaceful     Tense        Delighted    Tense        Peaceful      
 Peaceful     Peaceful     Peaceful     Other        Other           
 Peaceful     Peaceful     Delighted    Tense        Tense        
1

There are 1 best solutions below

0
jay.sf On

Try making factors in columns with unique values as levels=.

> dat[1:5] <- lapply(dat[1:5], factor, levels=unique(unlist(dat[1:5])))
> t(sapply(dat[1:5], table)) |> proportions(margin=1L)
              Peaceful     Other     Tense Delighted
area1_affect 0.8333333 0.1666667 0.0000000 0.0000000
area2_affect 0.8333333 0.0000000 0.1666667 0.0000000
area3_affect 0.5000000 0.1666667 0.0000000 0.3333333
area4_affect 0.0000000 0.3333333 0.6666667 0.0000000
area5_affect 0.3333333 0.3333333 0.3333333 0.0000000

Data:

> dput(dat)
structure(list(area1_affect = c("Peaceful", "Other", "Peaceful", 
"Peaceful", "Peaceful", "Peaceful"), area2_affect = c("Peaceful", 
"Peaceful", "Peaceful", "Tense", "Peaceful", "Peaceful"), area3_affect = c("Peaceful", 
"Other", "Peaceful", "Delighted", "Peaceful", "Delighted"), area4_affect = c("Tense", 
"Other", "Tense", "Tense", "Other", "Tense"), area5_affect = c("Peaceful", 
"Other", "Tense", "Peaceful", "Other", "Tense")), class = "data.frame", row.names = c(NA, 
-6L))