DEV Community

CoderLegion
CoderLegion

Posted on • Originally published at kodblems.com

Error in rbind(deparse.level, ...) : numbers of columns of arguments do not match

#r

Problem :
I have about 25 dataframes which are essentially the frequency counts of my elements stored in the column called Elements. They all have some of the different and some of the same elements in my Elements columns so they just look like below :

dataframe called DataFrame1

Elements freq
boby 4324234
janey 433
hamy 4324
timy 22
dataframe called DataFrame1
Elements freq
boby 987
janey 223
jonny 12
jimy 98092
I am just trying to set up the table so that my Elements becomes my column and each row is my frequencies. This is so that I should be able to combine all my dataframes.

I have tried rbind on them but facing the below error:

“Error in rbind(deparse.level, ...) : numbers of columns of arguments do not match”.

Solution :

An alternative method to the rbind + dcast technique is that the use of the tidyverse.

Please use the pipes (%>%) to first use the bind_rows() to bind all the dataframes together while simultaneously creating the dataframe id column here I just called the variable as "df". Then use the spread() to move the unique " Elements" values to become the column names and spreading your values of the "freq" across your new columns. " Elements" is the key and "freq" is your value in this case.

Top comments (0)