Once you have the frequencies, the next step is often to compute proportions: the share of the sample represented by each category. Because count() returns a tibble, we can easily extend it using mutate():
library (dplyr)
songs %>%
count (THEME) %>%
mutate (prop = n / sum (n))
THEME n prop
1 Heartbreak 145 0.145
2 Life_and_death 131 0.131
3 Love 139 0.139
4 Party_songs 162 0.162
5 People_and_places 145 0.145
6 Politics_and_protest 141 0.141
7 Sex 131 0.131
8 <NA> 6 0.006
This creates a new column prop containing the relative frequency of each category.
You can also turn proportions into percentages:
songs %>%
count (THEME) %>%
mutate (
prop = n / sum (n),
pct = prop * 100
)
THEME n prop pct
1 Heartbreak 145 0.145 14.5
2 Life_and_death 131 0.131 13.1
3 Love 139 0.139 13.9
4 Party_songs 162 0.162 16.2
5 People_and_places 145 0.145 14.5
6 Politics_and_protest 141 0.141 14.1
7 Sex 131 0.131 13.1
8 <NA> 6 0.006 0.6
This approach is more explicit and easier to read than prop.table(table(x)).
Please enable JavaScript to experience the dynamic code cell content on this page.
Make a frequency table and a proportion table for the variable YEAR with dplyr functions.
Please enable JavaScript to experience the dynamic code cell content on this page.
songs %>%
count (YEAR) %>%
mutate (
prop = n / sum (n),
pct = prop * 100
)
YEAR n prop pct
1 1916 1 0.001 0.1
2 1922 1 0.001 0.1
3 1928 6 0.006 0.6
4 1929 2 0.002 0.2
5 1931 2 0.002 0.2
6 1932 2 0.002 0.2
7 1935 1 0.001 0.1
8 1936 1 0.001 0.1
9 1938 2 0.002 0.2
10 1939 3 0.003 0.3
11 1940 1 0.001 0.1
12 1941 2 0.002 0.2
13 1944 2 0.002 0.2
14 1946 2 0.002 0.2
15 1949 1 0.001 0.1
16 1950 2 0.002 0.2
17 1951 3 0.003 0.3
18 1952 1 0.001 0.1
19 1953 1 0.001 0.1
20 1954 4 0.004 0.4
21 1955 3 0.003 0.3
22 1956 9 0.009 0.9
23 1957 3 0.003 0.3
24 1958 6 0.006 0.6
25 1959 10 0.010 1.0
26 1960 5 0.005 0.5
27 1961 14 0.014 1.4
28 1962 7 0.007 0.7
29 1963 17 0.017 1.7
30 1964 27 0.027 2.7
31 1965 33 0.033 3.3
32 1966 37 0.037 3.7
33 1967 33 0.033 3.3
34 1968 39 0.039 3.9
35 1969 31 0.031 3.1
36 1970 23 0.023 2.3
37 1971 30 0.030 3.0
38 1972 27 0.027 2.7
39 1973 24 0.024 2.4
40 1974 27 0.027 2.7
41 1975 23 0.023 2.3
42 1976 18 0.018 1.8
43 1977 27 0.027 2.7
44 1978 25 0.025 2.5
45 1979 34 0.034 3.4
46 1980 25 0.025 2.5
47 1981 19 0.019 1.9
48 1982 18 0.018 1.8
49 1983 25 0.025 2.5
50 1984 22 0.022 2.2
51 1985 18 0.018 1.8
52 1986 17 0.017 1.7
53 1987 18 0.018 1.8
54 1988 15 0.015 1.5
55 1989 19 0.019 1.9
56 1990 10 0.010 1.0
57 1991 10 0.010 1.0
58 1992 14 0.014 1.4
59 1993 11 0.011 1.1
60 1994 18 0.018 1.8
61 1995 12 0.012 1.2
62 1996 7 0.007 0.7
63 1997 8 0.008 0.8
64 1998 7 0.007 0.7
65 1999 11 0.011 1.1
66 2000 12 0.012 1.2
67 2001 7 0.007 0.7
68 2002 12 0.012 1.2
69 2003 14 0.014 1.4
70 2004 9 0.009 0.9
71 2005 15 0.015 1.5
72 2006 14 0.014 1.4
73 2007 16 0.016 1.6
74 2008 19 0.019 1.9
75 NA 6 0.006 0.6
Back to top