1

I am trying to extract only unique values of a certain column in a data frame. Here is an example:

df <- data.frame(word1=c("not","but","not","not","never","nor","never","not"),
      word2=c("beautiful","nice","strong","awesome","beautiful","beautiful","strong","nice"),
      n=c(400,378,29,10,222,43,620,90))

df

I would like to filter the second column "word2" to only contain unique words, so only that "beautiful" appears one time and that the column "n" adds together all the counts for all "beautiful", "strong" etc.

So it should like this:

df.unique <- data.frame(word2=c("beautiful","nice","strong","awesome"),
             n=c(665,468,649,10))
df.unique

In this example the column "word2" only contains 4 words but my real data frame contains thousands of words so i cannot use operators like "==beautiful,strong..."

Thank you very much in advance!

Lucinho91
  • 175
  • 2
  • 4
  • 16

0 Answers0