Reputation: 1930
Hello I have a dataframe record in R of dimension 8 obs 60 variables , with the missing values replaced by NA and the other values being words.
When I try to tabulate the dataframe like this feeds<-table(record)
I get an error saying :
Error in table(record) : attempt to make a table with >= 2^31 elements
Some sample elements/structure of my dataframe are
INC - CORP Application Issue INC - CORP Issue INC - PC Software Issue
Affected User Affected User Affected User
Attachment Attachment Attachment
Description / Priority Business Critica.. Configuration Item
Knowledge Search Client ID Contact Info
NA Description / Pr.. NA
I don't understand the error as the elements in the dataframe are clearly not even close to 2^31.
Thanks for your time.
Upvotes: 7
Views: 37807
Reputation: 105
I also had this issue. What worked for me was by converting each column in the dataframe into a numeric or character using the following lines:
df$x = as.numeric(as.character(df$x))
df$y = as.numeric(as.character(df$y))
df$z= as.numeric(as.character(df$z))
This will remove the factor levels in each of the variables within the dataframe. If you need the factor levels, I would not recommend doing this, but if you just need the raw values this will work well.
Upvotes: 0
Reputation: 110
its old topic but it might help someone else that reason I posting it. I had the same problem and I found it online solution from somewhere I don't remember and it worked for me perfectly. hopefully works for someone who needs.
solution<-as.data.frame(table(unlist(record)))
Upvotes: 6
Reputation: 171
I had this same problem. What worked for me was removing the NA's like this
df <- df[!is.na(df)]
Upvotes: 0
Reputation: 1994
The main issue is the complicating levels in your data frame. There are two ways to get around this problem:
invoke droplevels
after subsetting the data.frame. For example:
feeds <- droplevels(record)
Use apply
family functions, like sapply
someone mentioned earlier. For example:
feeds <- apply(record,1,table) # output stored as an object feeds
Good luck.
Upvotes: 0
Reputation: 23024
Your current code is trying to make a 60-dimensional table, returning the counts of every unique combination of the 60 variables. Thus the > 2^31 elements error.
Do you want sapply(record, table)
to tabulate each variable individually?
Upvotes: 3