I have a dataframe known as Tgame
containing two columns game
and hours_played
. I am trying to remove duplicates in the column game
and also sum up the average for column hours_played
for game column.
Asked
Active
Viewed 58 times
-2

s_baldur
- 29,441
- 4
- 36
- 69

Fenibo Tonye
- 1
- 1
-
1Please give a [mre] in your question! Read https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – jogo Oct 21 '19 at 11:20
1 Answers
1
Should be as simple as this (using data.table
):
library(data.table)
setDT(Tgame)[, mean(hours_played), by = game]

s_baldur
- 29,441
- 4
- 36
- 69
-
Thanks a lot. one question then how do you check the top 20 games with high hours played – Fenibo Tonye Oct 21 '19 at 11:39
-
@FeniboTonye Assuming you have used the solution above then `Tgame[order(hours_played, decreasing = TRUE)][1:20]` should do. – s_baldur Oct 21 '19 at 11:54
-
How about to write a code to show hours played >= 14 and show only 20 result – Fenibo Tonye Oct 21 '19 at 12:40
-
so i got the mean hours_played from that first code help. now how do i check the tp 10 high mean – Fenibo Tonye Oct 22 '19 at 12:42
-
If you have another question then please search for the answer here on Stackoverflow and Google and if you cannot find it open a new question. – s_baldur Oct 22 '19 at 12:50