Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error with bind_rows on list: "Column `Chr` can't be converted from integer to character"

Tags:

r

dplyr

I have a list containing 40 tbl_df and am trying to combine all elements of the list into a single data frame using bind_rows(). All elements have the same number of columns and columns have the same names. I have already generated an ID column containing the name of each element of the list, so no need to use the ID argument.

Upon running the command, bind_rows(list), I get this error:

Column Chr can't be converted from integer to character.

Chr in this case stands for "Chromosome" not character and these values should remain as an integer. Is dplyr automatically trying to coerce to character due to the column name being "Chr?" If so, how do I avoid dplyr doing this? It doesn't make sense that the command would be doing this, but I'm not sure what else could be going on.

FYI, this works perfectly fine when I try to combine just the first two elements of the list explicitly, i.e. bind_rows(list$element1, list$element2).

***This is my first SO question and I am new to R and coding in general. Please excuse me if I am breaking rules relating to posting. Let me know how to improve my post/question and I am happy to fix in the future.

like image 441
kadys Avatar asked Nov 08 '22 15:11

kadys


1 Answers

I had almost exactly this question today, and I got some good suggestions. Instead of copy-pasting other people's solutions here, I'll just link to my question and its answers.

Error in bind_rows_(x, .id) : Column can't be converted from factor to numeric

If this is not what you needed, please comment on this answer, and I will remove it.

like image 185
asterdroid Avatar answered Nov 15 '22 06:11

asterdroid