- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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?
To return a logical value for a t test based on 0.05 level of significance in R, we can follow the below steps −
- First of all, create a data frame with one column.
- Apply t.test function with ifelse to return logical value based on 0.05 level of significance.
Example1
Create the data frame
Let's create a data frame as shown below −
x<-rnorm(20) df1<-data.frame(x) df1
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
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
Apply t.test to get the logical return
Using t.test with ifelse to return logical output based on significance level 0.05 for less than alternative −
x<-rnorm(20) df1<-data.frame(x) ifelse(t.test(df1$x,mu=10,alternative="less")[["p.value"]]<0.05,"Yes","No")
Output
[1] "Yes"
Example 2
Create the data frame
Let's create a data frame as shown below −
y<-rpois(20,5) df2<-data.frame(y) df2
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
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
Apply t.test to get the logical return
Using t.test with ifelse to return logical output based on significance level 0.05 for greater than alternative −
y<-rpois(20,5) df2<-data.frame(y) ifelse(t.test(df2$y,mu=10,alternative="greater")[["p.value"]]<0.05,"Yes","No")
Output
[1] "No"
- Related Articles
- 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 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 disable a TestNG test based on a condition?
- How to find the power of t test in R?
- How to extract a data frame’s column value based on a column value of another data frame in R?
- How to get row index based on a value of an R data frame column?
- How to apply one sample t-test on all columns of an R data frame?
- How to select of data.table based on substring of row values for a column in R?
- How to replace the values in a matrix with another value based on a condition in R?
- How to find the position of a data frame’s column value based on a column value of another data frame in R?
- How to find the frequency for all columns based on a condition in R?

Advertisements