Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing objects to return results in an error

Tags:

r

I expected the following code to return the lower and upper bounds of a 95% confidence interval:

confint95 = function(mean, se)
{
  confint = abs(se*1.96)
  lower = abs(mean-cint)
  upper = abs(mean+cint)
  return(lower,upper) 
}

But this gives this message:

Error in return(lower, upper) : multi-argument returns are not permitted

How can I set function to return the lower and upper bounds of a 95% confidence interval?

like image 387
luciano Avatar asked Aug 04 '12 07:08

luciano


People also ask

What is object object error in JavaScript?

[object Object] is a string version of an object instance. This value is returned by a JavaScript program if you try to print out an object without first formatting the object as a string.

What happens when an object is passed by value C++?

Pass by value means "What you get is the value of the parameter", and pass by reference means "What you get is a reference/alias of the parameter", independently of what the compiler really does (Copying, moving, eliding copies, passing pointers, passing references, etc).

How do you pass an object in a new error?

The constructor for an Error object expects a string, not an object (which is why your scheme doesn't work). You are free to add your own custom properties to the Error object after you create it. let err = new Error('Email already exists'); err. status = 400; err.


2 Answers

Function will return the last expression. If you think for a moment without return. If you gave the function as the last expression to be evaluated

lower, upper

it would produce an error. If you have IDE it would also probably complain about a syntax error. You would solve that by combining the two elements with a c as @Andrie indicated. Ergo, you need to pass a single object. I often use lists to output different data structures. In your case, a vector is more than sufficient.

like image 64
Roman Luštrik Avatar answered Oct 20 '22 02:10

Roman Luštrik


to reurn two or more results, use "c"

dummy <- function(){
  a <- 1
  b <- 22
  return(a,b)
}

dummy()

# Error in return(a, b) : multi-argument returns are not permitted

dummy2 <- function(){
  a <- 1
  b <- 22
  return(c(a,b))
}

dummy2()
# [1]  1 22
like image 33
Captain Tyler Avatar answered Oct 20 '22 04:10

Captain Tyler