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
.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
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
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
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
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
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)
@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
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
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 + (
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
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
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
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
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
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.
> *
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
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
18 matches
Mail list logo