NAs introduced by coercionError in mutate_impl(.data, dots) : Column `XY` must be length 96 (the number of rows) or one, not 8

It's a bit hard to tell what's going wrong from this script (since it's not insubstantial). Are you able to go through it by steps and isolate the problematic area?

Somewhere in a mutate call in there you're using something that isn't the same length as (or from) your dataframe. If you pass a vector of length one, it applies itself to the whole column (which is why it's saying length 96 or one). Because we don't have the data, it's hard to tell exactly where.

Ideally, you could create a minimal reproducible example, aka a reprex. It will help us help you if we can be sure we're all working with/looking at the same stuff.


If you've never heard of a reprex before, you might want to start by reading the help page. The reprex dos and don'ts are also useful.

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "")

For pointers specific to the community site, check out the reprex FAQ.

1 Like