[R] Programming/scripting with "expressions - variables"
james.holtman@convergys.com
james.holtman at convergys.com
Mon Feb 7 16:48:33 CET 2005
Here is one way. It is the custom to return a value that will be assigned
to the variable, so I changed your 'macro' to a function that returns the
value and then assigns it to your variable:
> test <- function(name, value){
+ .result <- NULL # initialize to NULL
+ .result[name] <- value
+ .result[paste('other_', name, sep='')] <- paste("other_", value,
sep='')
+ .result
+ }
> Gregor <- test('Gorjanc', '25')
> Gregor # print out the vector
Gorjanc other_Gorjanc
"25" "other_25"
>
__________________________________________________________
James Holtman "What is the problem you are trying to solve?"
Executive Technical Consultant -- Office of Technology, Convergys
james.holtman at convergys.com
+1 (513) 723-2929
"Gorjanc Gregor"
<Gregor.Gorjanc at bfro. To: <r-help at stat.math.ethz.ch>
uni-lj.si> cc:
Sent by: Subject: [R] Programming/scripting with "expressions - variables"
r-help-bounces at stat.m
ath.ethz.ch
02/07/2005 09:52
Hello to Rusers!
I am puzzled with R and I really do not know where to look
in for my problem. I am moving from SAS and I have difficulties
in translating SAS to R world. I hope I will get some hints
or pointers so I can study from there on.
I would like to do something like this. In SAS I can write
a macro as example bellow, which is afcourse a silly one but
shows what I don't know how to do in R.
%macro test(data, colname, colvalue);
data &data;
...
&colname="&colvalue";
other_&colname="other_&colvalue";
run;
%mend;
And if I run it with this call:
%test(Gregor, Gorjanc, 25);
I get a table with name 'Gregor' and columns 'Gorjanc',
and 'other_Gorjanc' with values:
Gorjanc other_Gorjanc
"25" "other_25"
So can one show me the way to do the same thing in R?
Thanks!
--
Lep pozdrav / With regards,
Gregor GORJANC
---------------------------------------------------------------
University of Ljubljana
Biotechnical Faculty URI: http://www.bfro.uni-lj.si
Zootechnical Department email: gregor.gorjanc <at> bfro.uni-lj.si
Groblje 3 tel: +386 (0)1 72 17 861
SI-1230 Domzale fax: +386 (0)1 72 17 888
Slovenia
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list