0
votes

I have to combine two large data frames df1 and df2 to one data frame in R. The rbind() function is computationally expensive. The Stack() function is preferable to use for large datasets, so I am using the Stack() function to stack the data frames one over the other to form one data frame like the following:

 library(Stack)
 a = Stack (df1, df2)

However, I get the following error:

1: ‘V1’: coerced to ordered factor
2: ‘V1’: factor levels expanded: check levels/codes!
3: ‘V13’: coerced to ordered factor
4: ‘V13’: factor levels expanded: check levels/codes!
5: ‘V14’: coerced to ordered factor
6: ‘V14’: factor levels expanded: check levels/codes!
7: ‘V15’: coerced to ordered factor
8: ‘V15’: factor levels expanded: check levels/codes!
9: ‘V16’: factor levels expanded: check levels/codes!

The class of both df1 and df2 data.frame and both the dataframes have the same column names and number of columns. Why am I still getting this error?

1
Are u getting error or warning message? - akrun
Sounds like V1 / V13 / V14 / V15 are factors in both data frames, but with different range of values. When combined, the factor levels have to be expanded to accommodate values from both data frames. Also, as per akrun's comment, these should be warning messages rather than errors. - Z.Lin
Not an answer to your question, but have you tried library(data.table); setDT(df1); setDT(df2); rbind(df1, df2) for performance? - Hugh
Thanks, @Z.Lin for the heads up - Asmita Poddar

1 Answers

1
votes

Yes, indeed, those were warning messages, which appeared due to factor levels of the first dataset having to be expanded to accommodate values from both data frames. Once, I made the factor levels of all columns of both data frames to be the same, The Stack() function worked properly.