I have a large data frame indicating the appearance of trigrams in a row, where rows are strings, trigrams are columns, and values indicate whether a trigram occurs in a row.
so something like this:
strs <- c('this', 'that', 'chat', 'chin')
thi <- c(1, 0, 0, 0)
tha <- c(0, 1, 0, 0)
hin <- c(0, 0, 0, 1)
hat <- c(0, 1, 1, 0)
df <- data.frame(strs, thi, tha, hin, hat)
df
I want to get all columns / trigrams that have 1 for a given row or given row.
So, for line 2, the string is this, the result is a data frame that looks like this:
str tha hat
1 this 0 0
2 that 1 1
3 chat 0 1
4 chin 0 0
How can i do this?
source
share