How to use R language apply to carry out t.test in batch
This article mainly introduces how to use the R language apply batch t.test related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this article on how to use R language apply batch t.test article will have a harvest, let's take a look.
Batch t.test
Read the data in the whole table based on R language, and t.test each row in turn. If it is written into a loop, the operation speed is very slow, so you can use the apply () function to help complete the calculation process.
For example, the following data, with 2000 rows and 6 columns, are used for t.test calculation of group A data and group B data:
> head (data,2) A1 A2 A3 B1 B2 B3TRINITY_DN100001_c0_g1 2.5 2.81 4.75 1.96 2.71 6.11TRINITY_DN100002_c0_g1 0.0 0.00 0.00 0.00 40.45 > dim (data) [1] 2000 6
The basic function is t.test (), and the return value p.value is extracted, and finally all p.value is assigned to the pvalue vector.
Pvalue=apply (data,1,function (x) t.test (x [1:3], x [4:6], paired = T) $p.value)
The pvalue for the first and second rows of data in the returned result is as follows:
> head (pvalue,2) TRINITY_DN100001_c0_g1 TRINITY_DN100002_c0_g1 0.7165794 0.4226497 on "how to use R language apply to batch t.test" this article is introduced here, thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to use R language apply to carry out t.test in batches". If you want to learn more knowledge, welcome to follow the industry information channel.