Hi everyone,
I have a list (data) that I want to apply a t-test on each of the component
[[1]]
rep_name rep_family gene distance Hepatocytes_B1 Hepatocytes_B3 Huh.7_B1 Huh.7_B2 T_score
14732 HERVK22-int LTR THSD7A 0 5.3682 4.74 4.5634 4.0869 0.72895
[[2]]
rep_name rep_family gene distance Hepatocytes_B1 Hepatocytes_B3 Huh.7_B1 Huh.7_B2 T_score
2565 HERVL40-int LTR ANKIB1 3238 7.2268 7.3056 7.2132 7.5750 -0.1279
2646 HERVL40-int LTR ANKIB1 2879 7.2268 7.3056 7.2132 7.5750 -0.1279
2673 HERVL40-int LTR ANKIB1 2355 7.2268 7.3056 7.2132 7.5750 -0.1279
2693 HERVL40-int LTR ANKIB1 2051 7.2268 7.3056 7.2132 7.5750 -0.1279
16782 HERVL40-int LTR PRKAR2B 0 6.4382 2.2347 7.6774 6.6859 -2.8452
[[3]]
rep_name rep_family gene distance Hepatocytes_B1 Hepatocytes_B3 Huh.7_B1 Huh.7_B2 T_score
990 L1PA15-16 LINE CFH 0 11.3796 13.2806 6.9655 7.1840 5.25535
1035 L1PA15-16 LINE CFH 0 11.3796 13.2806 6.9655 7.1840 5.25535
7078 L1PA15-16 LINE KLHL13 152805 5.3824 4.7007 7.0668 6.8522 -1.91795
[[4]]
rep_name rep_family gene distance Hepatocytes_B1 Hepatocytes_B3 Huh.7_B1 Huh.7_B2 T_score
11062 LTR13 LTR SLC22A16 0 1.8176 2.4619 3.0775 2.0936 -0.44580
14322 LTR13 LTR POLR2J 929 7.6368 8.2278 9.5044 9.8754 -1.75760
22284 LTR13 LTR CACNG3 11594 2.6007 2.4943 1.8240 1.2075 1.03175
[[5]]
rep_name rep_family gene distance Hepatocytes_B1 Hepatocytes_B3 Huh.7_B1 Huh.7_B2 T_score
9719 LTR22A LTR CD38 0 5.8011 6.9873 5.7066 2.5126 2.28460
15293 LTR22A LTR THSD7A 0 5.3682 4.7400 4.5634 4.0869 0.72895
the thing that I tried was:
ttest <- for(i in 1:length(data)){
var1 <- data[[i]][5:6]
var2 <- data[[i]][7:8]
t.test(var1,var2)
}
but it gives me an error.However when I try for example to run the test bit by bit(on the second element in the list)
var1 <- data[[2]][5:6]
var2 <- data[[2]][7:8]
t.test(var1,var2)
It works perfectly, does someone has an idea where I m getting it wrong?
Thanks
Firstly:
What error is thrown?
What is the value of
i
at the point when the error is thrown?Are the input values all the same for
data[[i]]
?it s just giving me a NULL as answer and for the input I don't know if it s logical but I thought I represents each list like
list[[1]]
,list[[2]]
,.. etc.I don't know if I am making sense
It is giving you
NULL
because for loops don't assign values to variables. You would have to uselapply()
for that, or manually build your results list inside the for loop.Thanks, I will try