0

I have a data frame whose column col2 as two or more values. Example:

col1 <- c(210,222)

col2 <- c((1A,1B),(1B,1A))

I have tried the following code in R which isn't giving the desired output. Any suggestions.

comp = (sort(col2, partial = NULL, na.last = TRUE, decreasing = FALSE,
                    method = c("quick"), index.return = TRUE))
comp <- data.frame(comp)

My desired output is (without splitting the values in col2) since I need to be able to count those values.

col1 <- c(210,222)

col2 <- c((1A,1B),(1A,1B))

example: if 210 & 222 have two names (James, Allen) & (Allen,James). I need the output to be (Allen, James) (Allen, James) to the corresponding ids 210 & 222.Below is a sample of my code. The above were just a hypothetical example.

Example

Thank you in advance.

alexa
  • 11
  • 2
  • Hi Alexa, `c((1A,1B),(1B,1A))` is not valid R code. It will be much easier to help if you provide at least a sample of your data with `dput(join)` or if your data is very large `dput(join[1:20,])`. You can [edit] your question and paste the output. Please surround the output with three backticks (```) for better formatting. See [How to make a reproducible example](https://stackoverflow.com/questions/5963269/) for more info. – Ian Campbell Jun 13 '20 at 19:40
  • @IanCampbell Yes I only gave an example. My R code is a join of the tables. I am attaching what the data looks like. Hope this helps clarify what I am looking to solve for. – alexa Jun 13 '20 at 22:20

0 Answers0