help in function in R akin to macro in SAS

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

help in function in R akin to macro in SAS

Changbin Du
Dear Whom it may concern,

I need help  to figure the "macro" function in R:  I need to plot the
different data sets by a plotxyf function, I want the title to be different
for different data set.


# get the data set
final.xyf<- xyf(data=as.matrix(my.final),
Y=classvec2classmat(final$outcome), xweight = 0.5, grid=somgrid(5, 4,
"hexagonal"))


#plot function
plotxyf<-function (data) {

plot(data, type="mapping", labels=final$target, col=final$outcome+1,,
main="Supervised: Mapping plot for data")

                                      }


#use the plotxyf function.
plotxyf(final.xyf)


But the result is not I expected, the title is "Supervised: Mapping plot for
data", not "Supervised: Mapping plot for final.xyf"

CAn anyone help me with this?

Thanks so much!

--
Sincerely,
Changbin
--

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: help in function in R akin to macro in SAS

Stuart Luppescu
On Tue, 2010-04-06 at 09:33 -0700, Changbin Du wrote:
> #plot function
> plotxyf<-function (data) {
>
> plot(data, type="mapping", labels=final$target, col=final$outcome+1,,
> main="Supervised: Mapping plot for data")

Change this to: main=paste("Supervised: Mapping plot for", data)

>
>                                       }
>
>
> #use the plotxyf function.
> plotxyf(final.xyf)

BTW, I think it's better not to use "data" as a function parameter,
since it has reserved use in the language.

--
Stuart Luppescu <[hidden email]>
University of Chicago

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: help in function in R akin to macro in SAS

Gang Liang
A small correction.

On Tue, Apr 6, 2010 at 9:43 AM, Stuart Luppescu <[hidden email]>wrote:

> On Tue, 2010-04-06 at 09:33 -0700, Changbin Du wrote:
> > #plot function
> > plotxyf<-function (data) {
> >
> > plot(data, type="mapping", labels=final$target, col=final$outcome+1,,
> > main="Supervised: Mapping plot for data")
>
> Change this to: main=paste("Supervised: Mapping plot for", data)
>

You might want to introduce a new variable, such data_name, then use (data
field will expand here)

main=paste("Supervised: Mapping plot for", data_name)

Or get the argument name somehow inside the function...

>
> >                                       }
> >
> >
> > #use the plotxyf function.
> > plotxyf(final.xyf)
>
> BTW, I think it's better not to use "data" as a function parameter,
> since it has reserved use in the language.
>
> --
> Stuart Luppescu <[hidden email]>
> University of Chicago
>
> ______________________________________________
> [hidden email] 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: help in function in R akin to macro in SAS

Thomas Lumley
In reply to this post by Stuart Luppescu
On Tue, 6 Apr 2010, Stuart Luppescu wrote:

> On Tue, 2010-04-06 at 09:33 -0700, Changbin Du wrote:
>> #plot function
>> plotxyf<-function (data) {
>>
>> plot(data, type="mapping", labels=final$target, col=final$outcome+1,,
>> main="Supervised: Mapping plot for data")
>
> Change this to: main=paste("Supervised: Mapping plot for", data)

Umm, no.  That will put the entire data set into the title

plotxyf<-function(data){

     data.name<-deparse(substitute(data))
    plot(data, type="mapping", labels=final$target, col=final$outcome+1,
       main=paste("Supervised: Mapping plot for", data.name)

}

might work

    -thomas

>>
>>                                       }
>>
>>
>> #use the plotxyf function.
>> plotxyf(final.xyf)
>
> BTW, I think it's better not to use "data" as a function parameter,
> since it has reserved use in the language.
>
> --
> Stuart Luppescu <[hidden email]>
> University of Chicago
>
> ______________________________________________
> [hidden email] 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.
>

Thomas Lumley Assoc. Professor, Biostatistics
[hidden email] University of Washington, Seattle

______________________________________________
[hidden email] 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.