5
votes

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.

1
It's not because of the naming of your Chr variable, try it with a toy list. It's generally not good practice to name things with names already used for things in R, even though the capital C makes a distinction. Can you either provide a reproducible example or a sample of the list? e.g. www.stackoverflow.com/help/mcveScransom

1 Answers

1
votes

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.