

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to return a logical value for a t test based on 0.05 level of significance in R?
<p>To return a logical value for a t test based on 0.05 level of significance in R, we can follow the below steps −</p><ul class="list"><li>First of all, create a data frame with one column.</li><li>Apply t.test function with ifelse to return logical value based on 0.05 level of significance.</li></ul><h2>Example1</h2><p style=""><strong>Create the data frame</strong></p><p>Let's create a data frame as shown below −</p><p><a class="demo" href="http://tpcg.io/l62pxeF0 " rel="nofollow" target="_blank"> Live Demo</a></p><pre class="prettyprint notranslate">x<-rnorm(20) df1<-data.frame(x) df1</pre><p>On executing, the above script generates the below output(this output will vary on your system due to randomization) −</p><pre class="result notranslate" style=""> x 1 0.44038858 2 1.08938356 3 -0.23627885 4 0.73953751 5 -0.55476732 6 0.97726848 7 0.25612436 8 -1.89827676 9 0.50333232 10 0.55482166 11 1.83279952 12 0.93609228 13 0.35048901 14 0.05136088 15 -0.89102106 16 1.06392349 17 -0.15777431 18 0.45506977 19 1.43752763 20 1.27393923</pre><h2>Apply t.test to get the logical return</h2><p style="">Using t.test with ifelse to return logical output based on significance level 0.05 for less than alternative −</p><p><a class="demo" href="http://tpcg.io/fornHGwA " rel="nofollow" target="_blank"> Live Demo</a></p><pre class="prettyprint notranslate">x<-rnorm(20) df1<-data.frame(x) ifelse(t.test(df1$x,mu=10,alternative="less")[["p.value"]]<0.05,"Yes","No")</pre><h3 style="">Output</h3><pre class="result notranslate">[1] "Yes"</pre><h2 style="">Example 2</h2><p style=""><strong>Create the data frame</strong></p><p>Let's create a data frame as shown below −</p><p><a class="demo" href="http://tpcg.io/MNQZU7Ks " rel="nofollow" target="_blank"> Live Demo</a></p><pre class="prettyprint notranslate">y<-rpois(20,5) df2<-data.frame(y) df2</pre><p>On executing, the above script generates the below output(this output will vary on your system due to randomization) −</p><pre class="result notranslate" style=""> y 1 5 2 5 3 5 4 3 5 8 6 3 7 5 8 8 9 7 10 6 11 2 12 7 13 3 14 4 15 5 16 6 17 11 18 9 19 4 20 6</pre><h2>Apply t.test to get the logical return</h2><p style="">Using t.test with ifelse to return logical output based on significance level 0.05 for greater than alternative −</p><p style=""><a class="demo" href="http://tpcg.io/cmXgiint " rel="nofollow" target="_blank"> Live Demo</a></p><pre class="prettyprint notranslate">y<-rpois(20,5) df2<-data.frame(y) ifelse(t.test(df2$y,mu=10,alternative="greater")[["p.value"]]<0.05,"Yes","No")</pre><h3 style="">Output</h3><pre class="result notranslate">[1] "No"</pre>
- Related Questions & Answers
- How to convert a correlation matrix into a logical matrix based on correlation coefficient in R?
- How to extract the p-value from t test in R?
- How to disable a TestNG test based on a condition?
- How to find critical value for one-sided and two-sided t test in R?
- How to perform paired t test for multiple columns in R?
- How to find the sample size for t test in R?
- How to apply t test on each row of an R data frame?
- How to find the power of t test in R?
- How to apply one sample t-test on all columns of an R data frame?
- How to get row index based on a value of an R data frame column?
- How to select of data.table based on substring of row values for a column in R?
- How to extract a data frame’s column value based on a column value of another data frame in R?
- How to group objects based on a value in JavaScript?
- How to find the frequency for all columns based on a condition in R?
- How to replace the values in a matrix with another value based on a condition in R?
Advertisements