#these are exmple datasets
library(openintro)
data(hsb2)
str(hsb2)
#these are exmple datasets
library(openintro)
data(hsb2)
str(hsb2)
https://www.glowe.com/
Someone gave me am example of how to write a simple function. This was great.
addition = function(num1,num2){
answer = num1+num2
return(answer)
}
addition(10,9)
addition(5,4)
However, when I tried to use it, I realized I want to use a text instead of a number in this way.
my_matching = function(dataname){
m.out1<-matchit(data=dataname,control~gpa,method="nearest",ratio=1,
m.order="random", caliper=0.25)
}
my_matching(ABC_data1x)
my_matching(ABC_data2x)
Could you advise how I can run this without an error?
Also, how about a case like this? I used $ and . to indicate which part has to be replaced but this is not R way (This would be in SAS).
my_matching = function(data_N){
m.out1<-
matchit(data=ABC_data&data_n.x,control~gpa,method="nearest",ratio=1,
m.order="random", caliper=0.25)
}
my_matching(1)
my_matching(2)
Thank you!
addition = function(num1,num2){
answer = num1+num2
return(answer)
}
addition(10,9)
addition(5,4)
Thanks Isaac!
Use "" if dealing with a string.
addition = function(x1){
x1 = 2+3
return(x1)
}
addition(”kaz”)
addition(”john”)
The first line creates a sequence variable. The second like selects the first 30 observations.
smalldata$suji <- 1:nrow(smalldata)
smalldata<-filter(smalldata,suji <= 30)
In SAS's datastep, this would be:
suji=_n_;
if suji <=30;
library(gmodels)
CrossTable(smalldata$control, smalldata$male)
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