0

I’m trying to unite two different columns: Type.1 and Type.2. Both have the same type (character) but when I try an inner_join() I get the following message:

library(dplyr)

type_united <- inner_join(data1$Type.1,data1$Type.2)
# no applicable method for 'inner_join' applied to an object of class "character"

I get the same mistake while trying a left_join() (sometimes Type.2 has a null value, so I figured it could solve the problem).

What could I do to unify these two columns into a single one?

zephryl
  • 14,633
  • 3
  • 11
  • 30
  • 5
    Welcome to SO! Please have a look how to make a [great MRE](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Judging from your code, it seems that you are trying to input the content of the columns directly into `inner_join` and also don't use 2 different data.frames. Joinas are performed on 2 data sets, have a look at the dplyr vignette: https://dplyr.tidyverse.org/articles/two-table.html – starja Feb 08 '23 at 11:44
  • 1
    To unite your type columns you could use e.g. `paste(data1$Type.1, data1$Type.2, sep = ".")` which will use a `"."` as the separator but feel free to choose your own. – stefan Feb 08 '23 at 11:49
  • Stefan, that is a great alternative solution, but unfortunately the plotting will have too many variables. I wanted to keep it a bit more concise, so keeping only the original character strings would be optimal (just single types, instead of them together). I wanted to count the total quantity of pokemon of each type, regardless of it being mixed or secondary. – Lucas K Feb 08 '23 at 13:03
  • Would something like `data1 %>% pivot_longer(cols =c('Type1', 'Type2')) %>% count(value)` be useful for your counting objective? – William Lima Feb 08 '23 at 17:44
  • The notion of join/merge is a table-centric (in R, `data.frame`-centric) operation, c.f., https://stackoverflow.com/q/1299871/3358272, https://stackoverflow.com/q/5706437/3358272. It is not something one does on strings. With strings, there is the notion of concatenating/combining, or in R parlance, `paste`ing them. I don't know which you want, and so long as this question is not reproducible, it's going to be difficult to give you much help. – r2evans Feb 09 '23 at 13:26

0 Answers0