R question

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!

R, basic function

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”)