Quantcast

How to get the input of a function right?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

How to get the input of a function right?

stella
Hi,

I wrote a function with three inputs fun(x,y,z).

x is a matrix of three vectors combined with cbind. e.g.

x1<-(1,2,3,4)
x2<-(2,3,4,5)
x3<-(3,4,5,6)

x<-cbind(x1,x2,x3)

y is a vector e.g
y<-c(7,8,9)

z is a real number e.g.
z<-2.5

If a give the function an input like this, I get 'NA' in return. If I give the function a vector e.g c(1,2,3) instead of 'x' the function works just fine.
Does anyone has an idea why the function would not except 'x' as an input?

Thank you very much!
Stella
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to get the input of a function right?

Michael Weylandt
This is quite difficult without being able to see the function f .....

Michael

On Thu, Mar 22, 2012 at 11:43 AM, stella <[hidden email]> wrote:

> Hi,
>
> I wrote a function with three inputs fun(x,y,z).
>
> x is a matrix of three vectors combined with cbind. e.g.
>
> x1<-(1,2,3,4)
> x2<-(2,3,4,5)
> x3<-(3,4,5,6)
>
> x<-cbind(x1,x2,x3)
>
> y is a vector e.g
> y<-c(7,8,9)
>
> z is a real number e.g.
> z<-2.5
>
> If a give the function an input like this, I get 'NA' in return. If I give
> the function a vector e.g c(1,2,3) instead of 'x' the function works just
> fine.
> Does anyone has an idea why the function would not except 'x' as an input?
>
> Thank you very much!
> Stella
>
> --
> View this message in context: http://r.789695.n4.nabble.com/How-to-get-the-input-of-a-function-right-tp4495879p4495879.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to get the input of a function right?

Petr Savicky
In reply to this post by stella
On Thu, Mar 22, 2012 at 08:43:00AM -0700, stella wrote:

> Hi,
>
> I wrote a function with three inputs fun(x,y,z).
>
> x is a matrix of three vectors combined with cbind. e.g.
>
> x1<-(1,2,3,4)
> x2<-(2,3,4,5)
> x3<-(3,4,5,6)
>
> x<-cbind(x1,x2,x3)
>
> y is a vector e.g
> y<-c(7,8,9)
>
> z is a real number e.g.
> z<-2.5
>
> If a give the function an input like this, I get 'NA' in return. If I give
> the function a vector e.g c(1,2,3) instead of 'x' the function works just
> fine.
> Does anyone has an idea why the function would not except 'x' as an input?

Hi.

Can you send also the function? Without it, it is hard
to guess the source of the error.

Petr Savicky.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to get the input of a function right?

Sarah Goslee
In reply to this post by Michael Weylandt
On Thu, Mar 22, 2012 at 11:55 AM, R. Michael Weylandt
<[hidden email]> wrote:
> This is quite difficult without being able to see the function f .....
>
> Michael

I thought we had a fortune about telepathy, but I can't find it in the
fortunes package.

Sarah
--
Sarah Goslee
http://www.functionaldiversity.org

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to get the input of a function right?

David Winsemius

On Mar 22, 2012, at 12:14 PM, Sarah Goslee wrote:

> On Thu, Mar 22, 2012 at 11:55 AM, R. Michael Weylandt
> <[hidden email]> wrote:
>> This is quite difficult without being able to see the function  
>> f .....
>>
>> Michael
>
> I thought we had a fortune about telepathy, but I can't find it in the
> fortunes package.

Using the partial matching features of the fortune() function and the  
search strategy " mind" for "mind-reading" and "mind reading" and to  
avoid "remind", I find these candidates:

 > fortune(" mind")

There are actual error messages, and until you show them, we can not  
help as the mind reading machine is currently off for repairs.
    -- Dirk Eddelbuettel (after reports about errors with R CMD check)
       R-help (July 2010)
#---------
You are going to need a few more sessions for this therapy to be  
useful, we cannot read your computer's mind, just interpret what you  
tell us. I don't want to jump ahead, but can you tell us the childhood  
of your crashes, etc.
    -- Romain Francois (in a 'psychotherapy' session trying to  
understand the sources of a useR's problems)
       R-help (November 2009)



>
> Sarah
> --
> Sarah Goslee
> http://www.functionaldiversity.org
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to get the input of a function right?

Robert Baer
In reply to this post by stella
Your definition of x1, x2 and x3 requires the c() function.  Try leaving
some space around operators for increased readability.

Remember that the that the result of operations on sets containing NA is
often set to "NA" as well.  My guess is that if you print out x it contains
NA and that your function does operations on x that are included in the
function result.

Rob

-----Original Message-----
From: stella
Sent: Thursday, March 22, 2012 10:43 AM
To: [hidden email]
Subject: [R] How to get the input of a function right?

Hi,

I wrote a function with three inputs fun(x,y,z).

x is a matrix of three vectors combined with cbind. e.g.

x1<-(1,2,3,4)
x2<-(2,3,4,5)
x3<-(3,4,5,6)

x<-cbind(x1,x2,x3)

y is a vector e.g
y<-c(7,8,9)

z is a real number e.g.
z<-2.5

If a give the function an input like this, I get 'NA' in return. If I give
the function a vector e.g c(1,2,3) instead of 'x' the function works just
fine.
Does anyone has an idea why the function would not except 'x' as an input?

Thank you very much!
Stella

--
View this message in context:
http://r.789695.n4.nabble.com/How-to-get-the-input-of-a-function-right-tp4495879p4495879.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


------------------------------------------
Robert W. Baer, Ph.D.
Professor of Physiology
Kirksville College of Osteopathic Medicine
A. T. Still University of Health Sciences
800 W. Jefferson St.
Kirksville, MO 63501
660-626-2322
FAX 660-626-2965

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to get the input of a function right?

stella
In reply to this post by Sarah Goslee
Hi Michael and Sarah,
 
Thank you for offering help. I finally managed to construct an example with all essentials of my problem:
 
x1<-c(1,2,3,4)
x2<-c(2,3,4,5)
x3<-c(3,4,5,6)
x<-rbind(x1,x2,x3)
time<-c(1,3,9)
fit<-function(xx,t,tcc){slope <- coefficients(lm(log(xx) ~ 0 + t))[1]
alpha<-slope-log(2)/tcc
return(alpha)
}
alpha<-fit(x,time,20)
 
At the moment the function output 'alpha' is calculated for x(x1=1,x2=2,x3=3). I would like to get 'alphas' for all four rows of x without using a for-loop. Is there any possibility to avoid a for-loop?
 
Thank you very much in advance,
Stella


Von: Sarah Goslee <[hidden email]>
An: R. Michael Weylandt <[hidden email]>
CC: stella <[hidden email]>; [hidden email]
Gesendet: 17:14 Donnerstag, 22.März 2012
Betreff: Re: [R] How to get the input of a function right?

On Thu, Mar 22, 2012 at 11:55 AM, R. Michael Weylandt
<[hidden email]> wrote:
> This is quite difficult without being able to see the function f .....
>
> Michael

I thought we had a fortune about telepathy, but I can't find it in the
fortunes package.

Sarah
--
Sarah Goslee
http://www.functionaldiversity.org
        [[alternative HTML version deleted]]


______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to get the input of a function right?

PIKAL Petr
Hi

>
>
> Hi Michael and Sarah,
>  
> Thank you for offering help. I finally managed to construct an example
> with all essentials of my problem:
>  
> x1<-c(1,2,3,4)
> x2<-c(2,3,4,5)
> x3<-c(3,4,5,6)
> x<-rbind(x1,x2,x3)
> time<-c(1,3,9)
> fit<-function(xx,t,tcc){slope <- coefficients(lm(log(xx) ~ 0 + t))[1]

You were quite close

fit<-function(xx,t,tcc){slope <- coefficients(lm(log(xx) ~ 0 + t))

Regards
Petr

> alpha<-slope-log(2)/tcc
> return(alpha)
> }
> alpha<-fit(x,time,20)
>  
> At the moment the function output 'alpha' is calculated for x
> (x1=1,x2=2,x3=3). I would like to get 'alphas' for all four rows of x
> without using a for-loop. Is there any possibility to avoid a for-loop?
>  
> Thank you very much in advance,
> Stella
>
>
> Von: Sarah Goslee <[hidden email]>
> An: R. Michael Weylandt <[hidden email]>
> CC: stella <[hidden email]>; [hidden email]
> Gesendet: 17:14 Donnerstag, 22.März 2012
> Betreff: Re: [R] How to get the input of a function right?
>
> On Thu, Mar 22, 2012 at 11:55 AM, R. Michael Weylandt
> <[hidden email]> wrote:
> > This is quite difficult without being able to see the function f .....
> >
> > Michael
>
> I thought we had a fortune about telepathy, but I can't find it in the
> fortunes package.
>
> Sarah
> --
> Sarah Goslee
> http://www.functionaldiversity.org
>    [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Loading...