Wilcox.test between data frames in R -


i want apply wilcox.test each row of 2 dataframes in r. instance, row 1 in df1 , row 1 in df2, see if differ significantly. have hundreds of rows , expect hundreds of p-values outcome. there 105 columns. not quite sure how write command test each of row pairs, since there hundreds of them. appreciated!

using following data example:

#2 numeric data.frames (all columns numeric) #5 rows , 100 columns set.seed(5) df1 <- as.data.frame(matrix(runif(500), nrow=5, ncol=100)) df2 <- as.data.frame(matrix(runif(500), nrow=5, ncol=100)) 

solution

#a single lapply enough run wilcox test each row lapply(1:nrow(df1), function(i) {   #you run wilcox.test each pair of rows , return p.value   wilcox.test(as.numeric(df1[i, ]), as.numeric(df2[i, ]))$p.value }) 

output:

> lapply(1:nrow(df1), function(i) { + wilcox.test(as.numeric(df1[i, ]), as.numeric(df2[i, ]))$p.value + }) [[1]] [1] 0.8690001  [[2]] [1] 0.1390142  [[3]] [1] 0.7479788  [[4]] [1] 0.5340455  [[5]] [1] 0.8459806 

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 -