Categories
Uncategorized

Frequency, Degree, Centrality – R

get.freq.table<-function(dfx){

	colnames(dfx)<-c("x","x");
	dfx<-rbind(dfx[1],dfx[2]);
	dfx<-as.data.frame(table(dfx))
	dfx<-dfx[with(dfx,order(-Freq)),]
	rownames(dfx) <- 1:nrow(dfx)
	dfx[3]<-dfx[2]/(sum(dfx[2]))
	dfx[4]<-cumsum(dfx[3])
	
	dfx[5] <-"NA"
	dfx[5][(dfx[4])<=0.33] <- 1
	dfx[5][(dfx[4]) > 0.33 & (dfx[4]) <= 0.66] <- 2
	dfx[5][(dfx[4]) > 0.66] <- 3

	dfx[6] <-"NA"
	dfx[6]<-dfx[2]/(nrow(dfx)-1)
	
	colnames(dfx)<-c("user","Freq","PcP","cSum","layer","CD")
	dfx<-data.frame(dfx$user,dfx$Freq,dfx$PcP,dfx$cSum,dfx$layer,dfx$CD)
	colnames(dfx)<-c("user","Freq","PcP","cSum","layer","CD")
	dfx
}

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s