0

Like the title, the question is very straightforward. (pardon my ignorance)

I have a column, character type, in a data table. And there are several different words/values stored, some of them only appear once, others appear multiple times.

How can I select out the ones that only appear once?? Any help is appreciated! Thank you!

  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Sep 24 '19 at 18:10

2 Answers2

3

One option would be to do a group by and then select the groups having single row

library(data.table)
dt1  <- dt[, .SD[.N == 1], .(col)]
akrun
  • 789,025
  • 32
  • 460
  • 575
2
library(dplyr)

df %>%
    group_by(column) %>%
    dplyr::filter(n() == 1) %>%
    ungroup()

Example:

data = tibble(text = c("a","a","b","c","c","c"))

data %>%
    group_by(text) %>%
    dplyr::filter(n() == 1) %>%
    ungroup()

# A tibble: 1 x 1
  text 
  <chr>
1 b   
yusuzech
  • 5,548
  • 1
  • 14
  • 31