Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Is there a function to get multiple frequency tables within a table in R

$
0
0

I would like to get multiple frequency tables within a single table.

Here is my data:

df<-read.table(text=" group	score	night	ticket	book	gender	course
A	Y	1	0	0	Male	M
A	Y	1	0	0	Female	N
A	N	1	1	1	Female	N
A	Y	2	1	1	Female	M
A	Y	2	1	1	Male	N
A	Y	2	0	0	Female	N
A	N	3	1	0	Male	N
B	N	3	1	1	Female	N
B	N	1	0	1	Female	M
B	Y	1	0	1	Female	M",header=TRUE)

and the output would be :

	Frequency	Percent
Group		
A	7	70
B	3	30
score		
Y	4	40
N	6	60
night		
1	5	50
2	3	30
3	2	20
book		
0	4	40
1	6	60
gender		
Female	7	70
Male	3	30
course		
M	4	40
N	6	60

I have used the following codes:

df%>%
group_by( group, score, night, ticket, book, gender, course) %>%
summarise(n = n()) %>%
mutate(freq = n / sum(n)

But it did not work for.


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>