I have the following fake-dataset, very similar to the real one:
Country <- c("Italy", "Italy", "Germany", "Germany", "Spain", "Spain", "France", "France")
Specialisation <- c("Cooperative", "Savings", "Cooperative", "Savings", "Cooperative", "Savings", "Cooperative", "Savings" )
TotalAssets <- c(12, 3, 45, 6, 34, 98, 23, 5)
df <- data.frame(Country = Country, Specialisation = Specialisation, TotalAssets = TotalAssets)
I want to calculate the differences in mean between the Total Assets of Savings and Cooperative banks, for each country.
This is the code I came up with, but it does not work.
t <- df %>% group_by(Country) %>% t.test(TotalAssets ~ Specialisation, alternative = "two.sided", var.equal = FALSE)
UPDATE:
I tried to use the code above belonging to @SALAR. I get the following error:
Error in t.test.formula(TotalAssets ~ Specialisation, alternative = "two.sided", : grouping factor must have exactly 2 levels
I transformed the "Specialisation" column in factor:
TotalAsset_df$Specialisation <- as.factor(TotalAsset_df$Specialisation)
I checked the levels:
levels(TotalAsset_df$Specialisation)
Output:
[1] "Cooperative bank" "Savings bank"
But still, when I execute the code, I get the following error:
Thanks to whoever is gonna help!