dataframe - Aggregate R data frame over count of a field: Pivot table-like result set -


i have data frame in following structure

channelid,authorid 1,32 28,2393293 2,32 2,32 1,2393293 31,3 3,32 5,4 2,5 

what want is

authorid,1,2,3,5,28,31 4,0,0,0,1,0,0 3,0,0,0,0,0,1 5,0,1,0,0,0,0 32,1,2,0,1,0,0 2393293,1,0,0,0,1,0 

is there way this?

the xtabs function can called formula specifies margins:

 xtabs( ~ authorid+channelid, data=dat)           channelid authorid  1 2 28 3 31 5   2393293 1 0  1 0  0 0   3       0 0  0 0  1 0   32      1 2  0 1  0 0   4       0 0  0 0  0 1   5       0 1  0 0  0 0 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -