R question

I am trying to create this function, but I think the problem parts are where I tried to put macro tokens (e.g., var1, var2, var3) within "".    I'm getting error messages.  Any suggestions welcome.  Rでファンクションを書いているのですが、” ”の間に、var1,var2,var3を入れるとエラーが出ます。どうしたらいいでしょうか? This is the error message:

Error in eval(cols[[col]], .data, parent.frame()) : 

object 'var3.y' not found

 

<ここから>

 

make_tables<-function(var1,var2,var3){
analysis_data %>%
mutate(difference=var3.y-var3.x) -> analysis_data_b
analysis_data_c<-filter(analysis_data_b,difference >= 0)

result01pre <-Summarize(var3.x ~ group.x, data= analysis_data_c)
result01pre$test_type<-"Pretest"
result01pre$surveyID<- "var2"
result01pre$tableID<- "var1"
result01pre$item<- "var3.x"
result01pre=subset(result01pre,select=c(tableID, surveyID, item,test_type,group.x,n,mean))

result01post<-Summarize(var3.y ~ group.y, data= analysis_data_c)
result01post$item<- "var3.y"
result01post$test_type<-"Posttest"
result01post=subset(result01post,select=c(item,test_type,group.y,n,mean))

result01diff<-Summarize(difference ~ group.x, data= analysis_data_c)
result01diff$item<- "difference"
result01diff$test_type<-"Difference"
result01diff=subset(result01diff,select=c(item,test_type,group.x,n,mean,sd))

all01<-merge(result01pre,result01post,by.x="group.x",by.y="group.y",all.x = TRUE, all.y = TRUE)
all01<-merge(all01,result01diff,by.x="group.x",by.y="group.x",all.x = TRUE, all.y = TRUE)
#Paired t-test algorithm

all01 %>%
mutate(t_score = (t_score=mean/(sd/sqrt(n)))) %>%
mutate(sig_test=case_when(
t_score < 1.96 ~"ns",
t_score >= 1.96 ~"sig")) ->all01
}}

kaz1 <- make_tables(30,1,miss_5_d_affects_n)

Leave a Reply