Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use R language apply to carry out t.test in batch

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report