0

I have a data frame of two columns having word and frequency.

enter image description here

i want a new data frame when duplicate word comes the frequency should ad up as happened with word great

enter image description here

These seems to be pretty straight forward but i am not able to do it. Any suggestion

joy_1379
  • 487
  • 3
  • 17

2 Answers2

0

You can use dplyr for this one:

library(dplyr)

word <- c("great", "good", "nice", "great")
freq <- c(2,4,5,6)
df <- data.frame(word = word, freq = as.numeric(freq)) 

df %>% group_by(word) %>%
  summarise(freq = sum(freq))
Thomas L.
  • 524
  • 1
  • 5
  • 17
0
aggregate(dat$freq, by=list(dat$word), FUN=sum)
Carbo
  • 906
  • 5
  • 23