0
Dice:
P<-c("Alemanha", "USA", "Alemanha", "USA", "USA", "França")
Citacoes<-c(1,5,8,0,9,20)
df<-data.frame(P,Citacoes)
Each P (country) represents 1 document and each document has an amount of Citacoes (citations) associated with it.
I need to group P and add Citações.
What do I get with the code below:
library(dplyr)
a<-
group_by(df,P)%>%
summarise(Total=sum(Citacoes))
a
But in addition, I also need to present, in the same table, a sum of the number of documents per country. In this case, "USA" has three documents, "Alemanha" has two documents and "França" has a.
That is, at the end I need a table with 3 columns pais, Total of Citacoes for pais associated and sum of documents.
Finally, I would like to create a new column with the average of Citacoes for pais, tried the mutate, but without success. And sort these data in descending order by the number of documents from each country.
I’m open to trying solutions beyond dplyr.
Grateful
Thank you! E to create a column that is the average quote per parent? I tried mutate, but I couldn’t. Finally, it would be interesting to also sort by the amount of the Count column...
– Gustavo Oliveira Pinto
@Gustavooliveirapinto No
summarise, just includeMedia = Total/Count. I’ll edit.– Rui Barradas
Rui, I tested it this way and it worked as well: a<- group_by(df,P)%>% summarise(Total=sum(Citations), Count = n()%>% mutate(ratio = Total / Count) a b=a[order(a$Count,decreasing=T),]
– Gustavo Oliveira Pinto