How to perform different repeated statistical analysis of each column with a loop in R?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to perform different repeated statistical analysis of each column with a loop in R?

bearlot
Hello, I am new in R for advanced applications and need a help for repeating calculations. I have some codes and I have some data of A,B,C,D. I am performing 4 different statistical analysis. All letter consists if 5 values in each column. For instance, A is (1:5,1), B is (6:10,1), C is (11:15,1) and D is (16:17,1). The statistical methods below works perfectly but I have 60 columns and need 4 different result of those 60 columns. To perform this, the only way I know is changing the column number (ie, A(1:5, 2) , B(1:5, 2), C(1:5, 2), D(1:5,2)) of A, B,C ,D until I get 60th column. However, this very time consuming and difficult. Is there any way to perform this analysis using the same test methods and setups, written in the code, by using loop or lapply?  Thank you.

Ps. Please consider that, the codes of wilcox and mann whitney codes must stay same since it is working for my case and give result of what is expected.

Best Regards,

A=sampletest[1:5,1];
B=sampletest[6:10,1];
C=sampletest[11:15,1];
D=sampletest[16:20,1];

#Dependent

wilcox.test(A,B, mu=0, alt="two.sided", paired=T,  conf.int=F,conf.level = 0.95, exact=F,correct=F)


wilcox.test(C,D,mu=0, alt="two.sided", paired=T,  conf.int=F,conf.level = 0.95, exact=F,correct=F)

#Mann-Whitney U Test-Unpaired-Independent across

library(coin)

groups = factor(c(rep("A", length(A)), rep("C", length(C))));
material = factor(c(rep("B", length(B)), rep("D", length(D))));
subject = c(A, C)
sides = c(B, D)

#Across Subjects

wilcox.test(subject ~ groups,mu=0, alt="two.sided", paired=F,  conf.int=T,conf.level = 0.95, exact=F,correct=F)

#Across Materials

wilcox.test(sides ~ material,mu=0, alt="two.sided", paired=F,  conf.int=T,conf.level = 0.95, exact=F,correct=F)