R -- the merge functions

Inner join:

Keep only when both datasets provide the data for the subject/row

merge(x=demographics, y=shipping,
by.x = name, by.y="name")

merge(x= demographics, y= shipping,
by="name")

#merge another way
#full join
kaz1<- merge(x=old,y=new, by ="STUID", all=TRUE) #left join kaz2<- merge(x=old,y=new, by ="STUID", all.x=TRUE)

How to export an Excel file (sheet) in R

The package openxlsx allows an easy deletion of existing Excel files and sheets.

library(openxlsx)

write.xlsx(x, "temp.xlsx", sheetName="merged data",
col.names=TRUE, row.names=TRUE, append=TRUE,overwrite=TRUE)

 

***

This below is about xlsx package.  It didn't work well when there are already existing files of the same name.  I couldn't find ways to override.

x is the name of a R dataset.

library(xlsx)

write.xlsx(x, "temp.xlsx", sheetName="merged data",
col.names=TRUE, row.names=TRUE, append=FALSE)

https://cran.r-project.org/web/packages/xlsx/xlsx.pdf

http://www.sthda.com/english/wiki/r-xlsx-package-a-quick-start-guide-to-manipulate-excel-files-in-r

 

Paid t-test result is the same as proc means t-test for the change score

Paired T-test returns the same results as the simple t-test.  Compare the results of PROC TTEST and PROC MEANS below.  The statistical test results are identical.

data exercise;
input Subject_ID $ Pretest Posttest Treatment $;
cards;
A 11 24 T
B 22 26 C
C 32 25 T
D 22 44 C
E 25 45 T
F 36 24 C
G 33 25 T
;
run;

data exercise2;
set exercise;
change=posttest-pretest;
run;

PROC TTEST;
paired pretest*Posttest;
RUN;

proc means data=exercise2 mean std min max n stderr prt;
var change;run;