Hi,
So I have a data frame, and I would like to add an additional column which shows the total sum of rows within the subgroups...
heres a simple example
grp hour
1 A 1
2 A 1
3 A 1
4 A 2
5 A 2
6 B 1
7 B 1
8 B 1
9 B 2
10 C 1
11 C 1
What I want is an additional row showing the number of rows with the respective unique values. Some like this...
grp hour #unique
1 A 1 3
2 A 1 3
3 A 1 3
4 A 2 2
5 A 2 2
6 B 1 3
7 B 1 3
8 B 1 3
9 B 2 1
10 C 1 2
11 C 1 2
Any help would be appreciated. Thanks!
So I have a data frame, and I would like to add an additional column which shows the total sum of rows within the subgroups...
heres a simple example
Code:
grp=c("A","A","A","A","A","B","B","B","B","C","C")
hour=c(1,1,1,2,2,1,1,1,2,1,1)
test=data.frame(grp,hour,score)
1 A 1
2 A 1
3 A 1
4 A 2
5 A 2
6 B 1
7 B 1
8 B 1
9 B 2
10 C 1
11 C 1
What I want is an additional row showing the number of rows with the respective unique values. Some like this...
grp hour #unique
1 A 1 3
2 A 1 3
3 A 1 3
4 A 2 2
5 A 2 2
6 B 1 3
7 B 1 3
8 B 1 3
9 B 2 1
10 C 1 2
11 C 1 2
Any help would be appreciated. Thanks!