Re: [R] Simple Function

2010-11-11 Thread rnick
Thanks! It worked fine. -- View this message in context: http://r.789695.n4.nabble.com/Simple-Function-tp3035585p3038017.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/l

Re: [R] Simple Function

2010-11-10 Thread David Winsemius
.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org ] On Behalf Of rnick Sent: woensdag 10 november 2010 7:51 To: r-help@r-project.org Subject: [R] Simple Function Hi guy

Re: [R] Simple Function

2010-11-10 Thread Nick Sabbe
ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of rnick Sent: woensdag 10 november 2010 7:51 To

[R] Simple Function

2010-11-09 Thread rnick
Hi guys, Very new to R and your help would be highly appreciated for the following problem. I am trying to create a simple function which registers values within an array through a for loop. These are the steps I have followed: 1) Declared 2 global matrices 2) Create function mat() with i as an

Re: [R] Simple Function

2010-11-09 Thread Michael Bedward
If you want to assign to a variable in your workspace, rather than a local variable in your function, you can use the <<- operator (double headed arrow) like this... mat <- function(i) { for (k in i:10) { y[k] <<- k+1 f[k] <<- y[k-1] / 2 } } Type ?"<<-" for the help page. Michael O

[R] Simple Function

2010-11-09 Thread rnick
Hi guys, Very new to R and your help would be highly appreciated for the following problem. I am trying to create a simple function which registers values within an array through a for loop. These are the steps I have followed: 1) Declared 2 global matrices 2) Create function mat() with i as

[R] simple function can't find weights

2010-10-20 Thread Dimitri Liakhovitski
Hello! Here is my data: x<-data.frame(y=rnorm(100,0,1),a=rnorm(100,1,1),b=rnorm(100,2,1),weights=runif(100)) data.for.regression<-x[1:3] names(data.for.regression) myweights<-x$weights I run simple weighted regression and everything is fine: reg1<-lm(y~., data.for.regression, weights=myweights)

Re: [R] Simple Function doesn't work?

2009-11-27 Thread Colin Millar
@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Colin Millar Sent: 27 November 2009 16:41 To: Anastasia; r-help@r-project.org Subject: Re: [R] Simple Function doesn't work? Hi, You would also make your code more efficient and possible more readable by doing ReturnsGrid

Re: [R] Simple Function doesn't work?

2009-11-27 Thread Colin Millar
oun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Anastasia Sent: 27 November 2009 16:01 To: r-help@r-project.org Subject: [R] Simple Function doesn't work? Hello, I am new to R program, therefore, I am sorry if this is a really stupid question. I wrote a simple func

Re: [R] Simple Function doesn't work?

2009-11-27 Thread Alain Guillet
Hi, If you execute the following code it works but I wouldn't use grid if I were you as a vector as this name is already used by R (check help(grid)) and it explains why you have to define it in the function. ReturnsGrid = function(x,y,m){ grid <- numeric(m) for (i in 1:m){ grid[i] <- x + (

Re: [R] Simple Function doesn't work?

2009-11-27 Thread baptiste auguie
Hi, The error message, Error in grid[i] <- x + (i - 1) * (y - x)/m : object of type 'closure' is not subsettable indicates that "grid" is actually known to R as a function (type grid to see its definition). You can define your own variable with the same name, but that needs to be done before t

Re: [R] Simple Function doesn't work?

2009-11-27 Thread Ista Zahn
Hi, You need to create the grid object before you can assign values to it. Try ReturnsGrid = function(x,y,m){ grid <- numeric() for (i in 1:m){ grid[i] <- x + (i-1)*(y-x)/m } grid } On Fri, Nov 27, 2009 at 11:00 AM, Anastasia wrote: > Hello, > > I am new to R program, therefore, I am sorry i

[R] Simple Function doesn't work?

2009-11-27 Thread Anastasia
Hello, I am new to R program, therefore, I am sorry if this is a really stupid question. I wrote a simple function and for some reason it doesn't work ReturnsGrid = function(x,y,m){ for (i in 1:m){ grid[i] <- x + (i-1)*(y-x)/m } grid } xx=ReturnsGrid(0,9,3) Thanks a lot! [[alternati

Re: [R] simple function with if -> lapply to dataframe

2007-10-10 Thread Julian Burgos
Hi Georg, The answer is in the warning message In if (x < 0) a <- -1 else a <- 1 : the condition has length > 1 and only the first element will be used Basically you are passing a vector of length>1 to a control flow expression (if() in this case) that requires only a vector of length one. See

Re: [R] simple function with if -> lapply to dataframe

2007-10-10 Thread Leeds, Mark (IED)
sage- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Georg Ehret Sent: Wednesday, October 10, 2007 3:43 PM To: [EMAIL PROTECTED] Subject: [R] simple function with if -> lapply to dataframe Dear R, I am writing a simple function to extract the sign of values and apply it to

Re: [R] simple function with if -> lapply to dataframe

2007-10-10 Thread Marc Schwartz
On Wed, 2007-10-10 at 15:43 -0400, Georg Ehret wrote: > Dear R, >I am writing a simple function to extract the sign of values and apply it > to a data frame (see below). Whatever I do I get error-messages... What is > wrong? > > Thanking you in advance, > Cheers, Georg. > *

Re: [R] simple function with if -> lapply to dataframe

2007-10-10 Thread James W. MacDonald
Hi Georg, Georg Ehret wrote: > Dear R, >I am writing a simple function to extract the sign of values and apply it > to a data frame (see below). Whatever I do I get error-messages... What is > wrong? The main problem here is you are ignoring existing functions that will do the job much bette

[R] simple function with if -> lapply to dataframe

2007-10-10 Thread Georg Ehret
Dear R, I am writing a simple function to extract the sign of values and apply it to a data frame (see below). Whatever I do I get error-messages... What is wrong? Thanking you in advance, Cheers, Georg. *** Georg Ehret Institute of Genetic Medicine Johns Hopkins University