Equation with specified values

I'm trying to create a function in R with the following formula:

#k= 3
mySum <- function(rin=12, cout=28, cin=20) {
output <- 1/3(rin * ((cin + cout+1)/(cin+1))-rin)
return(output)
}

I want the output to return the value with the inputs specified, rin= 12, cout= 28, cin=20- but I just get an 'attempt to apply a non-function' error. Any help?

Hi @graceahey,

I think you are just missing an arithmetic operator (e.g. +, *, etc.) after 1/3. See below for a working example that uses *:

mySum <- function(rin = 12, cout = 28, cin = 20) {
  output <- 1/3 * (rin * ((cin + cout + 1) / (cin + 1)) - rin)
  return(output)
}

mySum()
#> [1] 5.333333
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.