Example using a R default data matcars.
library(MatchIt)
m.out0<-matchit(data=mtcars,am~hp+drat,exact=c("vs"),method="nearest", ratio=1, m.order="random", caliper=0.25)
m.out0
Example using a R default data matcars.
library(MatchIt)
m.out0<-matchit(data=mtcars,am~hp+drat,exact=c("vs"),method="nearest", ratio=1, m.order="random", caliper=0.25)
m.out0
Set two datasets (the two datasets must have identical variables)
total<-rbind(a,b)
Keep the rows I want.
subset(products, profit > 12)
Summarize()
# SINGLE AGGREGATE
#sapply(abc[c("GrowthMindset", "SelfEfficacy", "MSelfEfficacy","MathAnxiety","TeacherUse")], mean)
#this just gets means
sapply(abc[c("GrowthMindset", "SelfEfficacy", "MSelfEfficacy","MathAnxiety","TeacherUse")], function(x) mean(x, na.rm=TRUE))
#this gives me a matrix of means
aggregate(cbind(GrowthMindset, SelfEfficacy, MSelfEfficacy) ~ treat, abc, function(x) mean(x, na.rm=TRUE))-> result1
#this gets me a full results
aggregate(cbind(GrowthMindset, SelfEfficacy, MSelfEfficacy, MathAnxiety,TeacherUse) ~ treat, abc,
function(x) c(sum=sum(x), mean=mean(x), min=min(x), q1=quantile(x)[2],
median=median(x), q3=quantile(x)[4], max=max(x), sd=sd(x)))
https://stackoverflow.com/questions/57023935/r-question-how-to-do-a-calculation-of-a-mean-off-multiple-columns-and-select-va/57023959#57023959
x2 <- transmute(mydata, circumference,
average_2items = rowMeans(cbind(age, circumference)),
age)
My example that worked.
> x2<-transmute(time1data,commonID,
+ GrowthMindset=rowMeans(cbind(q0008_0001, q0008_0002, q0008_0003, q0008_0004, q0008_0005, q0008_0006, q0008_0007, q0008_0008)),
+ SelfEfficacy=rowMeans(cbind(q0009_0001, q0009_0002, q0009_0003, q0009_0004, q0009_0005))
+ )
In SAS, this would be:
newvariable=mean(of x1, x2, x3, x4);
Stockoverflow
R
Approach 1:
x2 <-subset(time1data,select=c(x1, x2, x3, x4, x5))
time1data$newvar<-rowMeans(x2,na.rm=TRUE)
Approach 2
time1data$newvar<-rowMeans(time1data[,c("q0008_0001", "q0008_0002", "q0008_0003", "q0008_0004", "q0008_0005", "q0008_0006", "q0008_0007", "q0008_0008")])
Approach 3
time1data$newvar<-rowMeans(time1data[,c("q0008_0001", "q0008_0002", "q0008_0003", "q0008_0004", "q0008_0005", "q0008_0006", "q0008_0007", "q0008_0008")],na.rm=TRUE)
ネットを参考にやってみました。
これがマクロでないもの。
time1data$teacher[time1data$CollectorNm=="Web Link 7"]<-"Smith"
FUNCTIONというのをつかえばいいかなと思ってやってみましたが、ダメでした、、。
kaz <- function(teachername,weblink){
time1data$teacher[time1data$CollectorNm==weblink]<-teachername
}
kaz("Smith","Web Link 7")
kaz("Adams","Web Link 8")
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)
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