Why do I get an error of can't make a table of more 2^31 elements in R

前端 未结 5 591
灰色年华
灰色年华 2020-12-10 16:37

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

相关标签:
5条回答
  • 2020-12-10 17:09

    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?

    0 讨论(0)
  • 2020-12-10 17:20

    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)))
    
    0 讨论(0)
  • 2020-12-10 17:30

    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.

    0 讨论(0)
  • 2020-12-10 17:34

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

    df <- df[!is.na(df)]
    
    0 讨论(0)
  • 2020-12-10 17:35

    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.

    0 讨论(0)
提交回复
热议问题