Em Ter 14 Ago 2012, Bert Gunter escreveu:
(Offlist, as my comments are not worth bothering the list about).
(offlist as well) :-)
R is what it is.
And it can even do things it was not designed for, including indirection
to internal data, through extensions.
Thanks.
--
Alexandre
--
-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
Namens Sachinthaka Abeywardana
Verzonden: dinsdag 14 augustus 2012 3:08
Aan: r-help@r-project.org
Onderwerp: [R] pass by reference
Hi all,
I want to do the following:
data-data.frame(col1=c(1,2,3,4,5))
getcol2-function(data){
data
On Mon, Aug 13, 2012 at 11:20:26PM -0300, Alexandre Aguiar wrote:
Sachinthaka Abeywardana sachin.abeyward...@gmail.com escreveu:
Think you are missing the point,
As lover of C-style pointers, I must admit that hiding complexities
(and associated problems) of pointers is a great feature of
You can use macros for this effect. Or environments:
daf - data.frame(a=1:10, b=rnorm(10))
env - as.environment(daf)
fun - function(x) x$c - x$a+x$b
fun(daf)
fun(env)
daf$c
env$c
You can see that the same function (fun) changes one object but leaves
another one unchanged. But before using it
(Offlist, as my comments are not worth bothering the list about).
I don't understand the purpose of this tirade (whose reasonableness I
make no judgment of). R is what it is. If you don't like it for
whatever reason, don't use it.
As a point of order, there are several packages that automate
Hi,
On Aug 14, 2012, at 10:07 AM, Bert Gunter wrote:
(Offlist, as my comments are not worth bothering the list about).
Almost off list!
I don't understand the purpose of this tirade (whose reasonableness I
make no judgment of). R is what it is. If you don't like it for
whatever reason,
Spotfire, TIBCO Software
wdunlap tibco.com
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf
Of rest
Sent: Tuesday, August 14, 2012 1:00 AM
To: 'Sachinthaka Abeywardana'; r-help@r-project.org
Subject: Re: [R] pass by reference
Hi
Hi all,
I want to do the following:
data-data.frame(col1=c(1,2,3,4,5))
getcol2-function(data){
data$col2[data$col1=2]=L
}
getcol2(data)
Unfortunately in the above col2 does not appear in the final data. So how
would you pass this by reference such that you would get it back?
Thanks,
You have to return the value of 'data' from the function. Functions
do not have side effects.
data-data.frame(col1=c(1,2,3,4,5))
getcol2-function(data){
+ data$col2[data$col1=2]=L
+ data # return value
+ }
getcol2(data)
col1 col2
11L
22L
33 NA
44 NA
55
Hi Jim, R,
What you just showed me simply prints out the 2nd column. If you inspect
your original data, it still just has 1 column. So its still passing by
value.
Thanks,
Sachin
On Tue, Aug 14, 2012 at 11:19 AM, jim holtman jholt...@gmail.com wrote:
You have to return the value of 'data' from
The assign the value back to the object:
data-data.frame(col1=c(1,2,3,4,5))
getcol2-function(data){
+ data$col2[data$col1=2]=L
+ data # return value
+ }
data - getcol2(data) # save the return value
data
col1 col2
11L
22L
33 NA
44 NA
55 NA
On Mon,
Think you are missing the point, assigning the value back is the same as
passing by value. This is rather inefficient if you ever have to deal with
large datasets. You dont want to keep having a local copy within the scope
of the function and then copying over the original.
On Tue, Aug 14, 2012
On Aug 13, 2012, at 9:23 PM, Sachinthaka Abeywardana
sachin.abeyward...@gmail.com wrote:
Hi Jim, R,
What you just showed me simply prints out the 2nd column. If you inspect
your original data, it still just has 1 column. So its still passing by
value.
Yes -- that's entirely by design.
On Aug 13, 2012, at 9:30 PM, Sachinthaka Abeywardana
sachin.abeyward...@gmail.com wrote:
Think you are missing the point, assigning the value back is the same as
passing by value. This is rather inefficient if you ever have to deal with
large datasets. You dont want to keep having a local
Then you can consider storing the object in an environment and
changing it there. If you like side effects, and passing by
reference, there is always C.
On Mon, Aug 13, 2012 at 9:30 PM, Sachinthaka Abeywardana
sachin.abeyward...@gmail.com wrote:
Think you are missing the point, assigning the
Sachinthaka Abeywardana sachin.abeyward...@gmail.com escreveu:
Think you are missing the point,
As lover of C-style pointers, I must admit that hiding complexities (and
associated problems) of pointers is a great feature of all successful high
level languages (HLLs). As much as they spare time
:
Sent: Monday, August 13, 2012 9:08 PM
Subject: [R] pass by reference
Hi all,
I want to do the following:
data-data.frame(col1=c(1,2,3,4,5))
getcol2-function(data){
data$col2[data$col1=2]=L
}
getcol2(data)
Unfortunately in the above col2 does not appear in the final data. So how
would you
0.553
A.K.
- Original Message -
From: Sachinthaka Abeywardana sachin.abeyward...@gmail.com
To: jim holtman jholt...@gmail.com
Cc: r-help@r-project.org
Sent: Monday, August 13, 2012 9:30 PM
Subject: Re: [R] pass by reference
Think you are missing the point, assigning the value back
18 matches
Mail list logo