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
--
Al
lt;<-data
> }
>
> <<- writes the result to the underlying environment. This is however
> generally seen as very bad programming (side effects).
> Greet'
> Frans-Oorspronkelijk bericht-
> Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project
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 reaso
(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" pa
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 i
On Mon, Aug 13, 2012 at 11:20:26PM -0300, Alexandre Aguiar wrote:
> Sachinthaka Abeywardana 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 lev
Frans-Oorspronkelijk bericht-
Van: r-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
-recode(x,'0="L";1="L";2="L"')
})
#user system elapsed
# 0.548 0.004 0.553
A.K.
- Original Message -
From: Sachinthaka Abeywardana
To: jim holtman
Cc: r-help@r-project.org
Sent: Monday, August 13, 2012 9:30 PM
Subject: Re: [R] pass by refe
: 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. S
Sachinthaka Abeywardana 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 and can be easily learned by
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
wrote:
> Think you are missing the point, assigning the value back is the same as
> pa
On Aug 13, 2012, at 9:30 PM, Sachinthaka Abeywardana
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 copy within the scope
> of
On Aug 13, 2012, at 9:23 PM, Sachinthaka Abeywardana
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. Look into functional prog
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 at
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
44
55
>
On
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 wrote:
> You have to return the value of 'data' from the function. Fu
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
44
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,
18 matches
Mail list logo