I have a data frame with the letters of the English alphabet and their frequency. Now it would be nice to also know the frequency of the vowels and the consonants and the total number of occurrences - and since I want to plot all of this information, I need it to be in one data frame.
So I often find myself in a situation like this:
df <- data.frame(letter = letters, freq = sample(1:100, length(letters)))
df_vowels <- data.frame(letter = "vowels", freq = sum(df[df$letter %in% c("a", "e", "i", "o", "u"), ]$freq))
df_consonants <- data.frame(letter = "consonants", freq = sum(df[!df$letter %in% c("a", "e", "i", "o", "u"), ]$freq))
df_totals <- data.frame(letter = "totals", freq = sum(df$freq))
df <- rbind(df, df_vowels, df_consonants, df_totals)
Am I doing this the right way or is there a more elegant solution for this?
Looks like my description was terribly confusing:
Basically, I want to add new categories (rows) to the data frame. In this very simple example, it's simply summarized data.
(For time series plots I'm using the aggregate function.)