Skip to content
Back to formatted view

Raw Message

Message-ID: <1344907825.44865.YahooMailNeo@web142601.mail.bf1.yahoo.com>
Date: 2012-08-14T01:30:25Z
From: arun
Subject: pass by reference
In-Reply-To: <CAGuusR99RT=a_bNLE-RPd4coE_x6M-aUF9WvhkdLXdAxcDGdFg@mail.gmail.com>

HI,
Try this:
getcol2<-function(data){
??? data$col2[data$col1<=2]="L"
?data
?}
data<-getcol2(data)
?data
#? col1 col2
#1??? 1??? L
#2??? 2??? L
#3??? 3 <NA>
#4??? 4 <NA>
#5??? 5 <NA>
A.K.



----- Original Message -----
From: Sachinthaka Abeywardana <sachin.abeywardana at gmail.com>
To: r-help at r-project.org
Cc: 
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 pass this by reference such that you would get it back?

Thanks,
Sachin

??? [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.