applying a function recursively on dataframes in r -


i have 2 dataframes:

df1:

    fruit     basket1   basket2   basket3   basket4  basket5     fruit1    10        9         3         5        1     fruit2    10        10        3        10        1     fruit3    1         10        10       1         10     fruit4    1         1         1        1         1     fruit5    2         2         3        3         3 

df2:

    fruit     basket1   basket2   basket3   basket4  basket5     fruit1    1         0         3         4        1     fruit2    9         10        3         1        1     fruit3    10        10        10        10       10     fruit4    1         10        1         1        1     fruit5    2         20        3         3        3 

i want save each row of df1 , df2 2 vectors , set wilcoxon test. right can manually, row row

a = as.numeric(as.vector(df1[1,])) b = as.numeric(as.vector(df2[1,])) wilcox.test(a,b)  = as.numeric(as.vector(df1[2,])) b = as.numeric(as.vector(df2[2,])) wilcox.test(a,b) 

and on ...

can me every row , generate table, df_result.

fruit   p_value fruit1   ... fruit2   ... 

df3 final output.

# design function wilcomx_p <- function(i){   <- as.numeric(as.vector(df1[i, -1]))   b <- as.numeric(as.vector(df2[i, -1]))   result <- wilcox.test(a,b)   return(result$p.value) }  # apply function, store results new data frame df3 <- df1[, 1, drop = false] df3$p_value <- sapply(1:nrow(df1), wilcomx_p) 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -