• Home
  • Recent Q&A
  • Java
  • Cloud
  • JavaScript
  • Python
  • SQL
  • PHP
  • HTML
  • C++
  • Data Science
  • DBMS
  • Devops
  • Hadoop
  • Machine Learning
in R Language by
Q:
Distinct number of observation in R language

1 Answer

0 votes
by

The function n() returns the number of observations in a current group. A closed function to n() is n_distinct(), which count the number of unique values.

In the next example, you add up the total of players a team recruited during the all periods.

# distinct values
data % > %
	group_by(teamID) % > %
	summarise(number_player = n_distinct(playerID)) % > %
	arrange(desc(number_player))
Code Explanation

  • group_by(teamID): Group by year and team
  • summarise(number_player = n_distinct(playerID)): Count the distinct number of players by team
  • arrange(desc(number_player)): Sort the data by the number of player

Related questions

+2 votes
asked Jul 28, 2019 in R Language by Aarav2017
+2 votes
asked Jul 28, 2019 in R Language by Aarav2017
...