[R] Complex summary of counts of rank positions over multiple dataframes

Johannes Radinger JRadinger at gmx.at
Thu Jun 14 14:40:14 CEST 2012


Hi,

I've kind of a tricky question, which I don't know how to solve yet:

I get multiple dataframes  loaded (readRDS) in a loop function. Each loaded dataframe contains two columns one with a var-name and one with a value. The rownumber (order) is very important as it is a value of the rank (1:x). 
A example with a similar looped structure:

df1 <- data.frame(var=c("A","B","C","D"),value=c(12,5,4,2))
df2 <- data.frame(var=c("B","A","G","C","J"),value=c(24,6,4,3,1))
df3 <- data.frame(var=c("A","B","D","K"), value=c(22,15,5,2))

df.list <- list(df1,df2,df3)

for(i in df.list){
	print(i)
}



Now I want to create a summary which should contain a list of all 'vars' (overall in all dataframes), and counts of their ranks. For the example: There are 7 unique 'vars' in all dataframes (A,B,C,D,G,J,K) and e.g.
A is two times on the first position and 1 time on the second rank etc.
A resulting dataframe could look like:
		uniquevars <- c("A","B","C","D","G","J","K")
		rank1a <- c(2,1,0,0,0,0,0)
		rank2a <- c(1,2,0,0,0,0,0)
		rank3a <- c(0,0,1,1,1,0,0)
		rank4a <- c(0,0,1,1,0,0,1)
		result_a <- data.frame(uniquevars,rank1a,rank2a,rank3a,rank4a)


In addition I would like to have for all populated 'cells' of the
result_a-dataframe the sum of the all 'values' from the original dataframes
instead of the counts.
Like:
		rank1b <- c(34,24,0,0,0,0,0)
		rank2b <- c(6,20,0,0,0,0,0)
		rank3b <- c(0,0,4,5,4,0,0)
		rank4b <- c(0,0,3,2,0,0,2)
		result_b <- data.frame(uniquevars,rank1b,rank2b,rank3b,rank4b)

		
Is there any common procedure to get counts of ranks for multiple dataframes?

Has anyone done similar things I can help me to get this done in a simple way considering the multiple dataframes in the loop?

/Johannes
-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a



More information about the R-help mailing list