[R] Help with functions - printing a variables name

2014-10-14 Thread Evan Kransdorf
Hello Everyone, I was wondering if someone could help me implement a function in R. I want to pass a vector x to my function, peform some math, then output the data. However, I want the output for x to be the *name of the vector I am *using as input. For example, data-c(1,5,10)

Re: [R] Help with functions - printing a variables name

2014-10-14 Thread Rui Barradas
Hello, Maybe something like data-c(1,5,10) func1-function(x) { nm - deparse(substitute(x)) y-x^2 z-x^3 out-data.frame(nm,y,z) return(out) } #function func1(data[1]) Hope this helps, Rui Barradas Em 14-10-2014 19:12, Evan Kransdorf escreveu: Hello Everyone, I was

Re: [R] Help with functions as arguments

2013-02-12 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 12/02/13 08:30, Ian Renner wrote: Hi, I am trying to write a function which defines some arguments, then uses those arguments as arguments of other function calls. It's a bit tricky to explain, so a simple example will have to suffice. I

Re: [R] Help with functions as arguments

2013-02-12 Thread Barry Rowlingson
On Tue, Feb 12, 2013 at 7:30 AM, Ian Renner ian_ren...@yahoo.com wrote: Where I am running into trouble is when I want to call function f1 within function f2: f2(x = 3, z = f1(x)) This returns the error: Error in f1(x) : object 'x' not found I'm not sure how to define environments

Re: [R] Help with functions as arguments

2013-02-12 Thread Jan T Kim
On Tue, Feb 12, 2013 at 09:38:19AM +0100, Rainer M Krug wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 12/02/13 08:30, Ian Renner wrote: Hi, I am trying to write a function which defines some arguments, then uses those arguments as arguments of other function calls. It's

Re: [R] Help with functions as arguments

2013-02-12 Thread Duncan Murdoch
On 13-02-12 5:34 AM, Jan T Kim wrote: On Tue, Feb 12, 2013 at 09:38:19AM +0100, Rainer M Krug wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 12/02/13 08:30, Ian Renner wrote: Hi, I am trying to write a function which defines some arguments, then uses those arguments as arguments of

Re: [R] Help with functions as arguments

2013-02-12 Thread Frans Marcelissen
...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Ian Renner Verzonden: dinsdag 12 februari 2013 8:30 Aan: r-help@r-project.org Onderwerp: [R] Help with functions as arguments Hi, I am trying to write a function which defines some arguments, then uses those arguments as arguments

Re: [R] Help with functions as arguments

2013-02-12 Thread David Winsemius
On Feb 12, 2013, at 12:38 AM, Rainer M Krug wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 12/02/13 08:30, Ian Renner wrote: Hi, I am trying to write a function which defines some arguments, then uses those arguments as arguments of other function calls. It's a bit tricky

[R] Help with functions as arguments

2013-02-11 Thread Ian Renner
Hi, I am trying to write a function which defines some arguments, then uses those arguments as arguments of other function calls. It's a bit tricky to explain, so a simple example will have to suffice. I imagine this has a simple solution, but perusing through environments and other help lists

Re: [R] help with functions

2009-09-05 Thread jonas garcia
Thanks Baptiste On Fri, Sep 4, 2009 at 5:13 PM, baptiste auguie baptiste.aug...@googlemail.com wrote: Hi, I think you've got a problem with environments, testA-function(input=1) { dat - data.frame(A=seq(input,5), B=seq(6,10)) vec.names- c(a, b) env - new.env()

Re: [R] help with functions

2009-09-05 Thread jim holtman
Try this variation; might have something to do with scope: testA-function(input) { dat- data.frame(A=seq(input,5), B=seq(6,10)) vec.names- c(a, b) for(i in 1:ncol(dat)) { tab- dat[,i]-1 assign(vec.names[i], tab) } do.call(rbind,

[R] help with functions

2009-09-04 Thread jonas garcia
Hi all, I have got 2 function (see bellow) which are simplifications of what I need to do. These functions are precisely the same, except for the last line. My question is, why doesn't function testA work in the same way as function testB. Both functions produce two objects, a and b that

Re: [R] help with functions

2009-09-04 Thread baptiste auguie
Hi, I think you've got a problem with environments, testA-function(input=1) { dat - data.frame(A=seq(input,5), B=seq(6,10)) vec.names- c(a, b) env - new.env() for(i in 1:ncol(dat)) { tab- dat[,i]-1 assign(vec.names[i], tab, env=env) }

Re: [R] help with functions spec and specprop

2009-08-23 Thread Uwe Ligges
Looks like nobody answered so far. If you want help: It is a good idea to say which package you are talking about. In a clean R session I get: specprop Error: object 'specprop' not found spec Error: object 'spec' not found hence no idea which functions from which package we are talking

[R] help with functions spec and specprop

2009-08-17 Thread mauede
I deal with mono-channel breathing signals sampled at 30[Hz] which are non-linear and non-stationary. My goal is to classify the signals according to common breathing patterns Trend remotion is necessary for cluster analysis but quite challenging. In fact, quasi-periodic patterns that span a

[R] Help with functions within a list

2009-03-20 Thread Altaweel, Mark R.
I will try to be clearer with what I wanted. What I am trying to do is take a list, say defined as res, that has a size of 1000 For example: res[[1]] res[[2]] .until res[[1000]] -- IdX Tick

Re: [R] Help with functions within a list

2009-03-20 Thread David Winsemius
I say again: Build a simple example; -- David Winsemius On Mar 20, 2009, at 1:00 PM, Altaweel, Mark R. wrote: I will try to be clearer with what I wanted. What I am trying to do is take a list, say defined as res, that has a size of 1000 For example: res[[1]]

Re: [R] Help with functions within a list

2009-03-20 Thread baptiste auguie
Agreed --- if you provided a working example it might be as simple as, library(reshape) recast(res, Id~Tick, fun=mean, id.var=c(Id, Tick), measure.var=X) which i had to test with this, res - list(read.table(textConnection( IdX Tick 1 2.2 1 2 3.1 1 1 1.2 2

[R] Help with functions

2008-10-22 Thread Alex99
Hi there, I have a the following function which takes a name(fname), total number of rows (Total), number of times to make a sample(nSample), number of records/rows to be included in each sample(nPatient). then it generates required samples and calculates the mean and standard deviation of the

Re: [R] Help with functions

2008-10-22 Thread Sarah Goslee
Hi, A repeatable example with data would help, as that way we could see what was happening. sampling=function(fname,Total,nSample,nPatient){ trans=t(A) What's A? It isn't one of the arguments to your function. And what's the transpose of a non-existent thing? You may well have it in your

Re: [R] Help with functions

2008-10-22 Thread jim holtman
It might be your return statement. Look up 'return' in the help file and you will see that you can only return a single value. If you want multiple values returned, use a list: return(listGmean,Gsd)) On Wed, Oct 22, 2008 at 11:53 AM, Alex99 [EMAIL PROTECTED] wrote: Hi there, I have a the

Re: [R] Help with functions (iterations)

2007-09-30 Thread Mark Wardle
Dear Letticia, Are you using R-help for your homework? See your previous postings: 1. 15th September: With a single R command complete the following: create a vector calles seqvec that repeats the sequence 1, 3,6, 10,15,21.( I was trying to use c() but this does not work) create a 5-row,

Re: [R] Help with functions (iterations)

2007-09-29 Thread jim holtman
I think this might be what you want: ex1.fcn-function(x){ h-4/(1+x^2) return(h) } my.pi - function(sample.size, sim.size, low, hi, func) { # create output vector result - numeric(sample.size) for (i in seq(sample.size)){ # loop for 'sample.size' times my.rand.x -