data <- data.frame( consumer_id = 1:40, age = c(23,25,26,27,24,28,30,29,22,25, 24,27,23,26,28,24,25,26,23,27, 29,24,28,27,22,26,24,25,23,27, 28,29,25,26,24,23,27,25,26,24), brand = rep(c(“Lincoln Financial”, “Prudential Financial”, “John Hancock”, “Principal Group”), each = 10), perception_score = c(4.6,3.9,4.2,3.8, 4.7,3.7,4.1,3.9, 4.5,3.8,4.0,3.7, 4.8,3.9,4.2,3.8, 4.6,3.8,4.1,3.7, 4.7,3.9,4.0,3.8, 4.5,3.8,4.2,3.9, 4.6,3.7,4.1,3.8, 4.7,3.9,4.0,3.7) )
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(readxl)
df <- read_excel("perceptions.xlsx")
colnames(df) <- trimws(colnames(df))
df$Age <- as.numeric(df$Age)
younger <- df %>%
filter(Age < 28) %>%
mutate(group = ifelse(brand == "Lincoln Financial", "Lincoln", "Competitors"))
head(younger)
## # A tibble: 4 × 5
## Consumer_id Age brand perception_score group
## <dbl> <dbl> <chr> <dbl> <chr>
## 1 1 22 Lincoln Financial 2 Lincoln
## 2 2 23 Prudential Financial 3 Competitors
## 3 3 21 John Hancock 2 Competitors
## 4 4 25 Principal Financial 1 Competitors
table(younger$group)
##
## Competitors Lincoln
## 3 1
t_test_result <- t.test(perception_score ~ group, data = younger, var.equal = TRUE)
print(t_test_result)
##
## Two Sample t-test
##
## data: perception_score by group
## t = 0, df = 2, p-value = 1
## alternative hypothesis: true difference in means between group Competitors and group Lincoln is not equal to 0
## 95 percent confidence interval:
## -4.968275 4.968275
## sample estimates:
## mean in group Competitors mean in group Lincoln
## 2 2