I have a data set as follows:
salary_old<-c(100,200,300,400,10000,100,10,20,30)
salary_new<-c(200,300,400,500,230,240,30,40,50)
d<-as.Date(c('2019-01-01','2019-01-02','2019-01-03'))
country<-c('USA','UK','IR')
id<-c('A','B','A')
data<-data.frame(id,country,d,salary_new,salary_old)
data<-data %>% arrange(id,country,d)
Then I want to calculate the T.test for the salary old and new for each group using loop or apply function to check if the p-value of each group is less than 0.05.
I wrote codes as follows:
z<-by(data,data$id,apply(data[,4:5],2,function(x,y){
t.test(x,y)
}))
could you please give me some advice. This the error that I got:
Error in eval(predvars, data, env) :
argument "y" is missing, with no default
I want the output will be like the follows:
id country p-value
A USA 0.9
A IR 0.9
B UK 0.34