I have a dataframe that has numeric and string values, for example:
mydf <- data.frame(id = c(1, 2, 1, 2, 3, 4),
value = c(32, 12, 43, 6, 50, 20),
text = c('A', 'B', 'A', 'B', 'C', 'D'))
The value of
id variable always corresponds to
text variable, e.g.,
id == 1 will always be
text == 'A'.
Now, I want to summarize this dataframe by
id (or by
text, since it's the same thing):
summarize(mean_value = mean(value))
This works nicely, but I also need the
text variable, since I wan t to do text analysis.
However, when I add
text to the dplyr pipe:
summarize(mean_value = mean(value),
text = text)
I get the following error:
Error: expecting a single value
id is always the same, is it possible to append it to the summarized dataframe?