data(sleep)
str(sleep)
## 'data.frame':    20 obs. of  3 variables:
##  $ extra: num  0.7 -1.6 -0.2 -1.2 -0.1 3.4 3.7 0.8 0 2 ...
##  $ group: Factor w/ 2 levels "1","2": 1 1 1 1 1 1 1 1 1 1 ...
##  $ ID   : Factor w/ 10 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
summary(sleep)
##      extra        group        ID   
##  Min.   :-1.600   1:10   1      :2  
##  1st Qu.:-0.025   2:10   2      :2  
##  Median : 0.950          3      :2  
##  Mean   : 1.540          4      :2  
##  3rd Qu.: 3.400          5      :2  
##  Max.   : 5.500          6      :2  
##                          (Other):8

#comparing paried samples

library(rstatix)
## 
## Attaching package: 'rstatix'
## The following object is masked from 'package:stats':
## 
##     filter
library(stringr)

sleep <- sleep %>%
  mutate(group = factor(group, labels = c("A", "B")))

A_group <- sleep %>%
  filter(group == "A") %>%
  select(extra)

B_group <- sleep %>%
  filter(group == "B") %>%
  select(extra)
t_test_A_and_B_group1 <- t.test(A_group$extra, B_group$extra, var.equal = TRUE)
t_test_A_and_B_group1
## 
##  Two Sample t-test
## 
## data:  A_group$extra and B_group$extra
## t = -1.8608, df = 18, p-value = 0.07919
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -3.363874  0.203874
## sample estimates:
## mean of x mean of y 
##      0.75      2.33

#The result shows that there is statiscially no difference between group A and group B