r - Group rows by attributes -


i have data frame containing data student lateness various classes. each row contains data late student , class: date , time of class, name of class, class size, number of minutes late, , gender of student. in order total percentage of late students classes, need count number of rows (late students) , compare total number of students attended class.

i can't sum class sizes of rows; count students of given class several times, once each late student in class. instead, need count each class size once each meeting of class.

example

key: minutes late, class name, students in attendance, gender of tardy student, minutes late.

11/12/10 stats 30 m 1 11/12/10 stats 30 m 1 11/12/10 stats 30 m 1 11/15/10 stats 40 f 3 11/15/10 stats 40 f 3 11/15/10 stats 40 f 3 11/16/10 radar 22 m 2 11/16/10 radar 22 m 2 11/16/10 radar 22 m 2 11/16/10 radar 22 m 2 11/16/10 radar 22 m 2 

in case, there 3 different class meetings , 11 late students. how make sure each class meeting's class size counted once?

if understand want correctly, easier plyr package, rather tapply or because understands amounts multivariate grouping. instance:

 ddply(df, .(date,class), transform, percent_late=length(minutes.late)/class.size)) 
argument length here can of column names. ddply split dataframe each combination of date , class factor levels. number of rows in each mini dataframe should correspond how many late students there (since there entry each late student). length(any variable) comes in. divide class size column fraction.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -