7

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.

Snedden27
  • 1,870
  • 7
  • 32
  • 60

5 Answers5

6

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)))
samet gok
  • 92
  • 1
  • 5
  • Can you please format the code with the code formatting tool? – Carlos Martinez Dec 06 '17 at 22:46
  • And maybe explain what this does and how it's different from `table(record)`. With that addition, it would be a very good answer! – Gregor Thomas Dec 07 '17 at 04:08
  • you could also do solution<-matrix(table(record)) the thing is I had a error which is Error in table(record) : attempt to make a table with >= 2^31 elements, my first solution solve the error there is not much difference as long as you don't get the error. – samet gok Dec 07 '17 at 05:31
3

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?

Sam Firke
  • 21,571
  • 9
  • 87
  • 105
  • Not sure if I am following you, I want to make the data frame as table as how it shows in the View(dataframe) I tried saapply ,seems like it gives me an list which doesn't look ordered into rows and colums – Snedden27 Feb 25 '15 at 14:14
  • Can you expand your example data to show column names and include an example of what your desired result would look like? I'm unclear on what you want. The `sapply` command should give you a list of tables, one for each of your variables, with the frequencies of values of that variable. – Sam Firke Feb 25 '15 at 14:22
  • The top row in the example are the column names, I think the table method doesn't like NA in the dataframe and it takes it as Null I just want to transform the dataframe into table as it is – Snedden27 Feb 25 '15 at 14:29
0

The main issue is the complicating levels in your data frame. There are two ways to get around this problem:

  1. invoke droplevels after subsetting the data.frame. For example:

    feeds <- droplevels(record)

  2. Use apply family functions, like sapply someone mentioned earlier. For example:

    feeds <- apply(record,1,table) # output stored as an object feeds

Good luck.

David C.
  • 1,974
  • 2
  • 19
  • 29
0

I had this same problem. What worked for me was removing the NA's like this

df <- df[!is.na(df)]
5tanczak
  • 161
  • 1
  • 2
  • 8
0

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.

Elletlar
  • 3,136
  • 7
  • 32
  • 38